Download multiple files as a zip-file using php

后端 未结 4 1546
醉梦人生
醉梦人生 2020-11-22 16:16

How can I download multiple files as a zip-file using php?

4条回答
  •  庸人自扰
    2020-11-22 16:47

    This is a working example of making ZIPs in PHP:

    $zip = new ZipArchive();
    $zip_name = time().".zip"; // Zip name
    $zip->open($zip_name,  ZipArchive::CREATE);
    foreach ($files as $file) {
      echo $path = "uploadpdf/".$file;
      if(file_exists($path)){
      $zip->addFromString(basename($path),  file_get_contents($path));  
      }
      else{
       echo"file does not exist";
      }
    }
    $zip->close();
    

提交回复
热议问题