1

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?

Thanks

user786731
  • 161
  • 2
  • 4
  • 11
  • 1
    What part do you need help with? Did you try going to the Zip/ZipArchive chapters of the [PHP manual](http://php.net)? A StackOverflow question should be a specific programming problem with a specific answer, not a description of a program you'd like to write. – Dan Grossman Jul 25 '11 at 15:54
  • Actually, you should be able to build the zip file in memory, instead of first saving it to disk and then deleting it again. This depends on the size, though. – Paŭlo Ebermann Jul 25 '11 at 15:59
  • Refer this similiar questions answer : http://stackoverflow.com/questions/5603851/how-to-create-a-zip-file-using-php-and-delete-it-after-user-downloads-it/17399319#17399319[enter link description here][1] [1]: http://stackoverflow.com/questions/5603851/how-to-create-a-zip-file-using-php-and-delete-it-after-user-downloads-it/17399319#17399319 – V A S Jul 01 '13 at 07:33

2 Answers2

4

http://php.net/manual/en/ref.zip.php

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));
       ob_clean();
       flush();
       readfile($file); 
       @unlink($file);
    

Code taken frome here: http://php.net/manual/en/function.readfile.php

blejzz
  • 3,349
  • 4
  • 39
  • 60
  • Although the question is worded poorly, this is just the solution I was looking for, and it worked! +1 – Gaʀʀʏ Nov 30 '12 at 03:25
0

read the location from $_GET and read all files under and create an array of files. than create a zip and download.

following link will help you http://www.tricksofit.com/2013/10/create-zip-file-php

Harish Singh
  • 3,359
  • 5
  • 24
  • 39