title: Bulk Select files - Zip Files - Then Download to client
body: <p>I can't seem to get anything working from what I am finding when I try to search for a solution with what I need to do.</p>
  
  <p>I am trying to create a form where a user will select 1 or more (bulk select all also) pdf files listed on a webpage. </p>
  
  <p>When the user click submit, I want to have my PHP download file Create a zip file, Add the selected pdf files (store on the server) to the zip file and then force download the zip file to the end user. </p>
  
  <p>When the user opens the zip file, the pdf files they selected from the webpage form are there for their use.</p>
  
  <p>Everything I find either does not work, is not secure or has something to do with uploading the files first which I don't want to do. The files are already stored on my server. </p>
  
  <p>Any help will be much appreciated.</p>
  
  <pre><code>&lt;code&gt;
  $files = array($_POST['file']);
  
  
          $zip = new ZipArchive();
          $filename = "practiceforms";
          $zip-&gt;open($filename,  ZipArchive::CREATE);
          foreach ($_POST['file'] as $key =&gt; $val)  {
            echo $path = "/images/docs/solutions/".$val.".pdf";
            if(file_exists($path)){
                $zip-&gt;addFile(basename($path),  file_get_contents($path));
            //$zip-&gt;addFromString(basename($path),  file_get_contents($path));  
            }
            else{
             echo"file does not exist";
            }
          }
          $zip-&gt;close();
  
          echo header('Content-Length: ' . filesize($filename));
          exit;
  &lt;/code&gt;
  </code></pre>