Hi everybody!
I have a problem. I'm uploading files to a directory on my harddrive, but I don't know how to do this check. It has to be done I guess otherwise I could ending up loosing the old file.
Check if there is already a file with the same name in the directory.
if there is a file with tha same name, I just want my name renamed to for example 1file.jpg or 2file.jpg or .....
then the check has to be done again until there is no file with the same name and my file can be uploaded.
Anybody has some suggestions how to start? Maybe somebody has already done a thing like that???
$target_dir is full path to upload directory $upload_file is desired filename $target_file is final (full) path for copy-statement: copy($upload_temp, $target_file)
while (file_exists($target_dir . $upload_file)) { $upload_file = "1".$upload_file; } $target_file = $target_dir . $upload_file;
Many thanks. Been sitting on this one for a while, but didn't get it right - and it was so easy and short.
Changed "1" for a rand funktion and it's working great!
Many thanks!!!!!!!!!!!!!!!!!!!