Kamal
Kamal

Reputation: 175

Overwrite image in php while uploading

I want to know that how can I overwrite images when they uploaded to server in php. For example I uploaded a photo to a folder as soon as I upload another image it will take place of previous image. Image name is not same it may differ. Thanks

Upvotes: 1

Views: 1738

Answers (1)

user3697460
user3697460

Reputation:

Delete the previous image before uploading the new one using:

$path = $_SERVER['DOCUMENT_ROOT'].'img/img.jpg';
unlink($path);

This code basically assigns the path of the image to $path and deletes the image using unlink($path);

Upvotes: 1

Related Questions