Jump to content

Recommended Posts

How would I handle the case that someone wants to upload a file that has a name that's already being used on the server? I don't want it to overwrite that file.

 

What are some of the things that you people (is that PC enough? lol) have done?

Link to comment
https://forums.phpfreaks.com/topic/62033-solved-uploading-images-through-php-form/
Share on other sites

add the current time after your image, this way the image never will have the same name and never will be overwritten

 

// 1. seperate the file to: array ( 'file', 'ext' )

// 2. gleu it together using: _123456.

// 3. result: file_123456.ext

 

$file = implode('_'.time().'.', explode('.', $_FILES['uploadname']['name']));

 

// only usable under file.ext condition, if you need a more complicated version pm me

1. nope, you don't have to change the filename, but when it exists it will be overwritten (btw: when using file_exists() results are cached, use clearstatcache() to clear the buffer)

2. time() gives the current time and will never be the same because it keeps counting up... (unless you can time travel)

3. done.

 

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.