Reputation: 15
When I upload an image file named boy.png
, it doesn't replace the existing boy.png
using move_uploaded_file()
.
The 2nd boy.png
is a different image.
How can I upload and replace the file if it's already exist using PHP?
Upvotes: 1
Views: 1101
Reputation: 38502
You can try this way to check first if the file with same name already exists or not? if that exits then remove the old one and upload the new one. Let's try like this way-
//checking if file with same name already exists
if(file_exists("pathtofile/boy.png")) unlink("pathtofile/boy.png");
//upload file now using the move_uploaded_file()
move_uploaded_file($fileLocTemporary, "pathtofile/boy.png"); # change as per your temp location
Upvotes: 1