title: Creating zip of multiple files and download in laravel
body: <p>i am using the following codes to make zip and allow user to download the zip    </p>
  
  <p>but its not working.it shows the error as ZipArchive::close(): Read error: Bad file descriptor.What might be the problem?i am working with laravel.</p>
  
  <pre class="lang-php prettyprint-override"><code>public function downloadposts(int $id)
  {
      $post = Post::find($id);
  
  
      // Define Dir Folder
      $public_dir = public_path() . DIRECTORY_SEPARATOR . 'uploads/post/zip';
      $file_path = public_path() . DIRECTORY_SEPARATOR . 'uploads/post';
      // Zip File Name
      $zipFileName = $post-&gt;post_title . '.zip';
      // Create ZipArchive Obj
      $zip = new ZipArchive();
      if ($zip-&gt;open($public_dir . DIRECTORY_SEPARATOR . $zipFileName, ZipArchive::CREATE) === TRUE) {
          // Add File in ZipArchive
          foreach ($post-&gt;PostDetails as $postdetails) {
              $zip-&gt;addFile($file_path, $postdetails-&gt;file_name);
          }
          // Close ZipArchive
          $zip-&gt;close();
      }
      // Set Header
      $headers = [
          'Content-Type' =&gt; 'application/octet-stream',
      ];
      $filetopath = $public_dir . '/' . $zipFileName;
      dd($filetopath);
      // Create Download Response
      if (file_exists($filetopath)) {
          return response()-&gt;download($filetopath, $zipFileName, $headers);
      }
  
      return redirect()-&gt;back();
  }
  
  </code></pre>