Jump to content

Rename of uploaded file


brown2005

Recommended Posts

I have a script that uploads a file from someones computer to my server.

say the file i have is 3.JPG

when i upload it, i want to change the name of the file to 1.JPG or 2.JPG to conincide with the id of the person uuploading the image.

any ideas please


toplay: Edited title to be more meaningful.
Link to comment
https://forums.phpfreaks.com/topic/4787-rename-of-uploaded-file/
Share on other sites

$upload = move_uploaded_file($_FILES[u]['picture'][/u]['tmp_name'], "[u]/home/www/htdocs/[b]$id[/b].jpg[/u]");

$_FILES['picture']['tmp_name'] is the temporary name on the server, change picture to the name of the form element that you are uploading with.

/home/www/htdocs/$id.jpg is the location, change /home/www/htdocs/ to match your file system structure, $id would be the variable holding the identification of the person and, of course, .jpg is the extension. $upload will be 1, if the upload was successful.

[i]EDIT -> Let me clarify the above, ['tmp_name'] should not be changed, it stands for the temporary name that the server is using to store the uploaded file, uploaded files are always moved to a temporary file and then moved to a permanent location. It doesn't pass the filename the user put in, if you wanted that name, it would just be ['name']...but that is useless unless you want to preserve the same file name; the only element of that code that will need changed is ['picture'] and the location and variable of the final location, as underlined above.[/i]
Link to comment
https://forums.phpfreaks.com/topic/4787-rename-of-uploaded-file/#findComment-16871
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.