Create a ZIP file download and delete it


I am looking to create a PHP script which will create a zip file from a location which will be a variable passed via $_GET. The location will be a folder which will then be zipped up and the user will be prompted to download the folder, after download the folder will need to automatically be deleted.

Can anyone help?


You could do something like this:

  • validate get
  • look up if the folder exists
  • zip the folder
  • read the newly created zip file and delete it at the end, like this:

       header('Content-Description: File Transfer');
       header('Content-Type: application/octet-stream');
       header('Content-Disposition: attachment; filename='.basename($file));
       header('Content-Transfer-Encoding: binary');
       header('Expires: 0');
       header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
       header('Pragma: public');
       header('Content-Length: ' . filesize($file));

Code taken frome here: