Top Ad unit 728 × 90

How to unlink existing image file using php | unlink() function in PHP to delete a file

 You can use the unlink() function in PHP to delete a file. The function takes the path of the file as its argument and deletes the file at that location.


Example:

$file_path = '/path/to/image.jpg';


if (file_exists($file_path)) {

    unlink($file_path);

    echo "The file has been deleted successfully.";

} else {

    echo "The file does not exist.";

}


It's also a good practice to check if file exist before unlink it, because unlink() function returns false if file doesn't exist or it's not writable.
How to unlink existing image file using php | unlink() function in PHP to delete a file Reviewed by Ashok Sen on 19:25:00 Rating: 5

No comments:

Website Design Company at Kolkata All Rights Reserved © 2014 - 2019
Developed by Asenwebmedia

Contact Form

Name

Email *

Message *

Powered by Blogger.