Jump to content

Renaming a User Selected File


ShoeLace1291

Recommended Posts

Ok, I have an upload script that allows users to upload images to the server/database.  My problem is that if a user uploads a file with the name of a file that already exists on the server, it overwrites the existing file.  If I have a script that randomly generates 3 letters/numbers, how would I insert those in between the file name and the file extension?  I'm thinking the solution would have something to do with implode, but I'm not sure how I would use it.

 

I'm using the $_FILES['upfile']['name'] variable.

 

Thanks for any help.

Link to comment
https://forums.phpfreaks.com/topic/72044-renaming-a-user-selected-file/
Share on other sites

You can check if the file exists by using the file_exists function prior to uploading.

 

Never done this so I can't be 100% sure. With the move_uploaded_file function you can specify the path. For example:

 

move_uploaded_file($_FILES['upfile']['name'],<where you want it/filename>)

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.