djfox Posted February 19, 2010 Share Posted February 19, 2010 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? Quote Link to comment Share on other sites More sharing options...
djfox Posted February 19, 2010 Author Share Posted February 19, 2010 I know there is a way to do it. No one here knows how? Quote Link to comment Share on other sites More sharing options...
jl5501 Posted February 19, 2010 Share Posted February 19, 2010 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. Quote Link to comment Share on other sites More sharing options...
djfox Posted February 19, 2010 Author Share Posted February 19, 2010 But how would I do that? Quote Link to comment Share on other sites More sharing options...
jl5501 Posted February 19, 2010 Share Posted February 19, 2010 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.