This Tutorial Has Been Viewed 2,441 Times.
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>";
You will also be interested in ,
- Convert Month Name To Month Number Using Simple php
- Export MySQL to CSV (Excel) using php
- How to split a word or sentence delimited with slashes, commas or hyphens
- Read text file reverse using php
- Ajax Page With PHP
- Email address validation using php
- Import large files in mysql using PhpMyAdmin
- Get filename and file extension using php
- Pass PHP Value To Javascript
- Randomly read and display values of an xml file using php
Categories: PHP