multiple folders zip using below code of PHP.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
<?php function get_all_directary($path){ $fileList = glob($path.'/*'); //Loop through the array that glob returned. foreach($fileList as $filename){ //Simply print them out onto the screen. if(is_dir($filename)){ get_all_directary($filename); }else{ $GLOBALS['fileArray'][count($GLOBALS['fileArray'])]=$filename; } } } $zipFileName="Archive.zip"; $serverPath=$_SERVER['DOCUMENT_ROOT']."/demo"; $zipFileSavePath=$serverPath."/".$zipFileName; //List of inut folder $inputZip[0]="img"; $inputZip[1]="img2"; $GLOBALS['fileArray'] = array(); for($i=0;$i<count($inputZip);$i++){ get_all_directary($inputZip[$i]); } $fileArray=$GLOBALS['fileArray']; unset($GLOBALS); $zip = new ZipArchive(); // Remove Zip file if exits if(file_exists($zipFileSavePath)) { unlink ($zipFileSavePath); } if ($zip->open($zipFileSavePath, ZIPARCHIVE::CREATE) != TRUE){ die ("Could not open archive"); } for($i=0;$i<count($fileArray);$i++){ $zip->addFile($fileArray[$i],$fileArray[$i]); // $zip->addFile('file path of server','file path of zip') } // close and save archive $zip->close(); |
More Stories
CPU & Memory usage in PHP
Install PHP mcrypt extension on Ubuntu
Text to speech