Created
May 25, 2011 01:01
-
-
Save ninetwentyfour/990112 to your computer and use it in GitHub Desktop.
Zip Folder PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Get the directory to zip | |
$filename_no_ext= $_GET['directtozip']; | |
// we deliver a zip file | |
header("Content-Type: archive/zip"); | |
// filename for the browser to save the zip file | |
header("Content-Disposition: attachment; filename=$filename_no_ext".".zip"); | |
// get a tmp name for the .zip | |
$tmp_zip = tempnam ("tmp", "tempname") . ".zip"; | |
//change directory so the zip file doesnt have a tree structure in it. | |
chdir('user_uploads/'.$_GET['directtozip']); | |
// zip the stuff (dir and all in there) into the tmp_zip file | |
exec('zip '.$tmp_zip.' *'); | |
// calc the length of the zip. it is needed for the progress bar of the browser | |
$filesize = filesize($tmp_zip); | |
header("Content-Length: $filesize"); | |
// deliver the zip file | |
$fp = fopen("$tmp_zip","r"); | |
echo fpassthru($fp); | |
// clean up the tmp zip file | |
unlink($tmp_zip); | |
?> | |
<a href="zip_folders.php?directtozip=THE USERS DIRECTORY">Download All As Zip</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment