I have a folder in my server. How do i zip the folder and download it using php.
Asked
Active
Viewed 3,578 times
0
-
1couple similar questions here on SO. http://stackoverflow.com/questions/4914750/how-to-zip-a-whole-folder-using-php http://stackoverflow.com/questions/5484347/how-to-zip-a-folder-and-download-it-using-php – Aaron W. Mar 30 '11 at 12:29
-
1Please point out why none of http://stackoverflow.com/search?q=zip+and+download+folder+[php] answered your question. – Gordon Mar 30 '11 at 12:36
-
See http://stackoverflow.com/questions/ask-advice – Gordon Mar 30 '11 at 12:45
1 Answers
2
See the PHP Zip methods.
Example from PHP manual pages:
<?php
$zip = new ZipArchive();
$filename = "./test112.zip";
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
exit("cannot open <$filename>\n");
}
$zip->addFromString("testfilephp.txt" . time(), "#1 This is a test string added as testfilephp.txt.\n");
$zip->addFromString("testfilephp2.txt" . time(), "#2 This is a test string added as testfilephp2.txt.\n");
$zip->addFile($thisdir . "/too.php","/testfromfile.php");
echo "numfiles: " . $zip->numFiles . "\n";
echo "status:" . $zip->status . "\n";
$ zip->close();
?>

Treffynnon
- 21,365
- 6
- 65
- 98