Posts

Showing posts from November, 2017

How to create a zip file in php?

$zip = new ZipArchive(); $file_name = "./myzip.zip"; if ($zip->open($file_name, ZIPARCHIVE::CREATE) !== TRUE) { exit("cannot open <$file_name>\n"); } try { //it will create new file add content $zip->addFromString("test_my_file.txt" . time(), "#1 String for testingsave as test_my_file.txt.\n"); //first part of original file and second part you wnat give name of file in zip $zip->addFile("test1.php", "test1.php") or die ("ERROR: Could not add file:"); $zip->addFile("test2.php", "test2.php") or die("ERROR: Could not add file:"); //test1.php and test2.php files must be exist } catch (Exception $e) { echo $e->getMessage(); exit; } echo "Zipped Files : " . $zip->numFiles . "\n"; echo "Status of Zip :" . $zip->status . "\n"; $zip->close();