title: How to zip a whole directory and download using php
body: <p>I am self studying php and I am creating a sample test site which lets the user input the file code which will be used to determine the file path of the folder to be downloaded. The code i have below will only download a single file. What i want now is to download and zip the whole directory. Please help. Thank you in advance</p>
  
  <pre><code>    &lt;h3&gt;Search Client File&lt;/h3&gt;
              &lt;form  method="post" action="#"  id="searchform"&gt;
                Type the Image Code:&lt;br&gt;&lt;br&gt;
                    &lt;input  type="text" name="icode"&gt;
              &lt;br&gt;
        &lt;input  type="submit" name="submit" value="Search"&gt;
              &lt;/form&gt;  
  
  &lt;?php
       $fcode=$_POST["icode"];
   if (!empty($fcode))
     {
  
  $file="/var/www/website/$fcode.tif";
  
       if (file_exists($file))
       {
  
         header('Content-Description: File Transfer');
         header('Content-Type: application/octet-stream');
         header('Content-Disposition: attachment; filename='.basename($file));
         header('Content-Transfer-Encoding: binary');
         header('Expires: 0');
         header('Cache-Control: must-revalidate');
         header('Pragma: public');
         header('Content-Length: ' . filesize($file));
         ob_clean();
         ob_end_flush();
         readfile($file);
  
        }
  
        else
        {
          echo "The file $fcode.tif does not exist";
        } 
     }    
  
       else
       {
         echo "No Values";
       }
  
      ?&gt;
  </code></pre>