I have a php form where multiple images care uploaded. The file names are checked against the current folder and if there is a match it stops, here’s a simplified version of what goes on:
if (file_exists("../uploads/" . $_FILES["file"]["name"][$i])){
echo "sorry that one already exists, rename";
}else{
move_uploaded_file($_FILES["file"]["tmp_name"][$i],"" . '../uploads/'.$_FILES["file"]["name"][$i]);
echo $_FILES["file"]["name"][$i]." was uploaded";
}
What I want is to ask “do you want to overwrite the existing file”? If they are OK with it, then proceed with move_uploaded_file(). This could be a pop-up or whatever. What is the best way to do this?
If you’re reading from
$_FILESthen the data has already been posted to the server. Technically it’s possible to return an error page to the user, asking them to confirm the overwrite, but it would be more elegant and efficient to check the existence of the filename/path via ajax before submitting the actual file data to the server.