1

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?

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.