Jump to content

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>)

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.