How to delete zip file after download complete in php?

by wilmer.lemke , in category: PHP General , a year ago

How to delete zip file after download complete in php?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by mac , a year ago

@wilmer.lemke 

To delete a zip file after it has been successfully downloaded in PHP, you can use the unlink() function to delete the file from the server.


Here is an example code snippet:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$file = '/path/to/your/file.zip';

// ... code for downloading the file here ...

// Deleting the file after download
if (file_exists($file)) {
    unlink($file);
    echo "File deleted successfully.";
} else {
    echo "File not found.";
}


Make sure to replace '/path/to/your/file.zip' with the actual path to the zip file you want to delete.


Note: Ensure that the script has the necessary write permissions to delete the file.