php - How to zip a files with dynamic paths or multiple paths? -


i have array multiple paths , have wrote code create .zip file.

here code:

 <?php   $array = array( "name" => "/sites/readme.txt",     "test" => "/sites/chessboard.jpg"  );   foreach($array $key => $value)  {     $test = $value ;      echo "zip started";     $zip = new ziparchive();      $ow = 1;     $file= "/sites/master.zip";     if($zip->open($file,$ow?ziparchive::overwrite:ziparchive::create)===true)     {         echo "zip entered if class";       // add files .zip file         $zip->addfile($test);      // $zip->addfile($value);      // closing zip file         $zip->close();          } }  ?> 

and problem in array $value having multiple file paths. code takes last file path , creating zip.

i want take paths , create zip file , store in folders.

maybe help. place loop in open zip statement.

$array = array( "name" => "/sites/readme.txt",     "test" => "/sites/chessboard.jpg" ); $file= "/sites/master.zip"; $zip = new ziparchive; echo "zip started.\n"; if ($zip->open($file, ziparchive::create) === true) {     foreach($array $path){         $zip->addfile($path, basename($path));         echo "$path added.\n";     }     $zip->close();     echo 'done'; } else {     echo 'failed'; } 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -