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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.