I am trying to check if a file (image) exists so I can delete it before uploading the new one. This is what i've tried so far:
foreach (glob("../imgs/" . $name . ".*") as $file) {
if (file_exists($file)) {
unlink($file);
}
}
Is this the correct way of doing this? Do I need to break the loop if a match is found? Would this perform badly if there are a lot of pictures in that folder?
Edit: sorry, i should have mention this: On upload the files get renamed with the user unique id, that's why if a user wants to upload another image i want to replace it with the existing one. (This images are used for profile pictures).