php zip all the files and folders on the same directory -


how zip files , folders on same directory using php zip ?

so have list of files , folders , zip php. sorry not familiar php zip , documentation on php net didnt much

you can use function make zip folder of files:

public function create_zip($files = array(),$destination = '',$overwrite = false) {     //if zip file exists , overwrite false, return false     if(file_exists($destination) && !$overwrite) { return false; }     //vars     $valid_files = array();     //if files passed in...     if(is_array($files)) {         //cycle through each file         foreach($files $file) {             //make sure file exists             if(file_exists($file)) {                 $valid_files[] = $file;             }         }     }     //if have files...     if(count($valid_files)) {         //create archive         $zip = new ziparchive();         if($zip->open($destination,$overwrite ? ziparchive::overwrite : ziparchive::create) !== true) {             return false;         }         //add files         foreach($valid_files $file) {             $zip->addfile($file,$file);         }         //debug         //echo 'the zip archive contains ',$zip->numfiles,' files status of ',$zip->status;          //close zip -- done!         $zip->close();          //check make sure file exists         return file_exists($destination);     }     else     {         return false;     } } 

here, $files contain files array. , $destination zip file location on server.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -