facebook twitter youtube
in PHP - 11 Jul, 2011, This Tutorial Has Been Viewed 4,596 Times.
by admin - no comments
Zip or Archive a directory using php
VN:F [1.9.22_1171]
Rating: 10.0/10 (1 vote cast)

This is a simple script that archive or zip the current directory using php. Just copy paste the code and run on your host or path where you need the archive to be created.

You can even pass the path as an argument using GET or POST method.

ini_set("max_execution_time", 1000);
$zip = new ZipArchive();
$file_name='my-archive.zip';
if ($zip->open($file_name, ZIPARCHIVE::CREATE) !== TRUE) {
die ("Could not open archive, MIGRATION FAILED");
}
//change the path to be archived accordingly, You can even give the path dynamically using GET or POST method.
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("./"));
foreach ($iterator as $key=>$value) {
$zip->addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key");
}
$zip->close();
echo "<h1><u>Archive Created Successfully.</u></h1>Download It <a href=".$file_name.">CLICK HERE</a><p>";

VN:F [1.9.22_1171]
Rating: 10.0/10 (1 vote cast)
Zip or Archive a directory using php, 10.0 out of 10 based on 1 rating

Incoming search terms:




coded by nessus

Leave a Reply

Close
Please support the site
By clicking any of these buttons you help our site to get better