title: Download multiple files as a ZIP - Laravel 7
body: <p><a href="https://i.stack.imgur.com/2ZRKk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2ZRKk.png" alt="enter image description here"></a></p>
  
  <p>If I <code>dd($files);</code></p>
  
  <p>I got </p>
  
  <pre><code>array:4 [▼
    0 =&gt; "/Users/jdoe/Sites/laravel7/public/img/portfolio/58-Admin-Site-Dashboard/126/full.jpg"
    1 =&gt; "/Users/jdoe/Sites/laravel7/public/img/portfolio/58-Admin-Site-Dashboard/127/full.jpg"
    2 =&gt; "/Users/jdoe/Sites/laravel7/public/img/portfolio/58-Admin-Site-Dashboard/128/full.jpg"
    3 =&gt; "/Users/jdoe/Sites/laravel7/public/img/portfolio/58-Admin-Site-Dashboard/130/full.jpg"
  ]
  </code></pre>
  
  <h1>download()</h1>
  
  <pre><code>public function download($id)
  {
  
      $portfolioImages = PortfolioImage::where('portfolio_id',$id)-&gt;get();
  
      $files = [];
      foreach ($portfolioImages as $i =&gt; $portfolioImage) {
          $files[$i] = public_path(). $portfolioImage-&gt;image_path;
  
      }
  
      // dd($files);
  
      $zip = new ZipArchive;
      $fileName = $id.'.zip';
      if ($zip-&gt;open(public_path($fileName), ZipArchive::CREATE) === TRUE)
      {
  
          foreach ($files as $key =&gt; $value) {
              $relativeNameInZipFile = basename($value);
              $zip-&gt;addFile($value, $relativeNameInZipFile);
          }
  
          $zip-&gt;close();
      }
  
      return response()-&gt;download(public_path($fileName));
  
  }
  </code></pre>
  
  <p>I kept getting this error </p>
  
  <blockquote>
    <p>ZipArchive::close(): Failure to create temporary file: Permission denied</p>
  </blockquote>
  
  <p>How do I prevent this error ? </p>