Reputation: 2531
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?
Upvotes: 0
Views: 1120
Reputation: 10467
You asked if you can do it from client side without uploading file to the server - the answer is - not that easy.
The only way you can do it is to create AJAX handler to which you'll pass the image file name and return the answer if file exists, then display popup accordingly.
Upvotes: 1
Reputation: 28174
If you're reading from $_FILES
then 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.
Upvotes: 1