Jump to content

Renaming a file that a user uploads to site?


djfox

Recommended Posts

My site allows for registered users to upload images to the site under their own gallery. Currently it just leaves the file named as however the person has it named. But what I would like to do is something another site does, which is rename the files when the user uploads them. An example of how I would like it done:

A user whose username is "I Like Cheese" uploads a file named "whatever.jpg", but in the uploading form, they title the upload "Dog In the Rain". I`d like like "whatever.jpg" to be renamed to "Dog In the Rain_by_I Like Cheese.jpg" upon the upload process and use that new filename for the database information.

 

How would I tell the system to rename the image file in that manner?

Link to comment
Share on other sites

in the upload code you have now, you will have a move_uploaded_file() somewhere, which will be copying the uploaded temp file to the final file name.

 

At that point, just before that function, you can construct the target filename as you would like.

Link to comment
Share on other sites

you need to find that code I mentioned.

 

By that point, you need to have the username available from the database. If you need help on that, I will need to know the structure of the user table.

 

Also you will need from the upload form, a field where the user can put the title.

 

Then you can put all this info together (converting spaces to _) and then save the file as its new name

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.