soycharliente Posted July 27, 2007 Share Posted July 27, 2007 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? Quote Link to comment Share on other sites More sharing options...
ramli Posted July 27, 2007 Share Posted July 27, 2007 You could use file_exists to validate the upload <?php $filename = '/path/to/foo.txt'; if (file_exists($filename)) { print "$filename exists"; } else { print "Het bestand $filename does not exists"; } ?> Quote Link to comment Share on other sites More sharing options...
ignace Posted July 27, 2007 Share Posted July 27, 2007 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 Quote Link to comment Share on other sites More sharing options...
soycharliente Posted July 27, 2007 Author Share Posted July 27, 2007 So I should force them to change the filename? Should I just change the filename for them and use some kind of number format that counts? Quote Link to comment Share on other sites More sharing options...
ignace Posted July 27, 2007 Share Posted July 27, 2007 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. 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.