If you want to Zip a directory in PHP? Use the below PHP program to zip a folder using PHP programming language.
Note: For using the below script, Windows users need to enable php_zip.dll inside of php.ini.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <?php //Enter the name of directory $pathdir = "Directory Name/"; //Enter the name to creating zipped directory $zipcreated = "test.zip"; //Create new zip class $newzip = new ZipArchive; if($newzip -> open($zipcreated, ZipArchive::CREATE ) === TRUE) { $dir = opendir($pathdir); while($file = readdir($dir)) { if(is_file($pathdir.$file)) { $newzip -> addFile($pathdir.$file, $file); } } $newzip ->close(); } ?> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.