Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create an empty zip archve by php

Tags:

php

how to create an empty zip archve by php some thing like new -> zip archive

like image 902
Mostafa Elkady Avatar asked Dec 02 '22 05:12

Mostafa Elkady


1 Answers

I use this code to return a zip file from an array of files to be zipped, if the array is empty, than it returns an empty zip archive, hope it helps.

function zipFiles($files){
  // "UEsFBgAAAAAAAAAAAAAAAAAAAAAAAA==" is the base64 encoded content of an empty zip archive
  if(count($files) == 0){
    return base64_decode("UEsFBgAAAAAAAAAAAAAAAAAAAAAAAA=="); 
  }
  $zip = new ZipArchive();
  ... do your stuff
  foreach($files as $file){
    ... do your stuff
  }
}
like image 167
DuccioM Avatar answered Dec 09 '22 11:12

DuccioM