Jump to content
Larry Ullman's Book Forums

Rename Uploaded File Based On Form Field Contents


Recommended Posts

I have searched everywhere for a "how to" for this. I need to be able to rename an uploaded file with data from form fields. For example, I have "catagory", "class" and "title" fields. I need the uploaded file (jpeg) to be renamed with the contents of these three fields. The form info is also stored in a database.

 

Thanks,

Darrel

Link to comment
Share on other sites

You need to use the move_uploaded_file function to both name the file and specify the file path for the file.

Details on the function can be found here:

http://php.net/manual/en/function.move-uploaded-file.php

 

Basically, post the form, and in the PHP script that is called from the form post, used the specified values to name the file.

For example:

move_uploaded_file($tmp_file, "/uploads/file_{$_POST['category']}_{$_POST['class']}_{$_POST['title']}");
Link to comment
Share on other sites

 Share

×
×
  • Create New...