For making the file name unique, I use this code to add an unique id at the end of filename:
if (!file_exists("data/$filename")) {$savingfile=$filename;} else {$savingfile="$filename-2";}
This method perfectly works, but what is the simple way to continue this loop if “$filename-2” exists save it as “$savefile-3” and so forth (to find an non-exist file name)?
1 Answer