Who can help me to fix the following problem? Here is the issue: in a form POST i made people can upload files. The code below check if in the \"uploads\" folder there another f
Just change the $FinalFilename
:
$FinalFilename = pathinfo($OriginalFilename, PATHINFO_FILENAME) . '_' . $FileCounter++ . '.' . pathinfo($OriginalFilename, PATHINFO_EXTENSION);
Or (better if you have a lot of files with the same name and often iterate more than once):
$filename = pathinfo($OriginalFilename, PATHINFO_FILENAME);
$extension = pathinfo($OriginalFilename, PATHINFO_EXTENSION);
while (file_exists( 'uploads/'.$FinalFilename ))
$FinalFilename = $filename . '_' . $FileCounter++ . '.' . $extension;