This Tutorial Has Been Viewed 2,441 Times.
VN:F [1.9.20_1166]
Rating: 0.0/10 (0 votes 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.20_1166]
Rating: 0.0/10 (0 votes cast)



coded by nessus
Categories: PHP

Leave a Reply