title: How to save download zip to public folder in laravel?
body: <p>I want to download a folder into ZIP format with my code below. </p>
  
  <p>Actually this work perfectly for download folder to zip only. </p>
  
  <p>But i want the zip file also save to public folder in public/folder. 
  i use laravel and ziparchive</p>
  
  <p>Please help me</p>
  
  <pre><code> public function downloadzip($id_pra) {
       $dcmt = DB::table('document')-&gt;select(DB::raw(" max(id) as id"))-&gt;where('id_praapplication',$id_pra)-&gt;groupBy('type')-&gt;pluck('id');
  
       $files = Document::whereIn('id', $dcmt)-&gt;get(); 
  
       $url = url('')."/storage/uploads/file/".$id_pra."/"; 
  
       # create new zip opbject
       $zip = new \ZipArchive();
  
       # create a temp file &amp; open it
       $tmp_file = tempnam('.','');
       $zip-&gt;open($tmp_file, \ZipArchive::CREATE);
       # loop through each file
  
       foreach($files as $file){
           $url2 = $url.$file-&gt;upload;
           $url2 = str_replace(' ', '%20', $url2);
  
           if (!function_exists('curl_init')){ 
               die('CURL is not installed!');
           }
  
           $ch = curl_init();
           curl_setopt($ch, CURLOPT_URL, $url2);
           curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
           $output = curl_exec($ch);
           curl_close($ch);
           $download_file = $output;
  
           $type = substr($url2, -5, 5); 
           #add it to the zip
           $zip-&gt;addFromString(basename($url.$file-&gt;upload.'.'.$type),$download_file);
       }
  
       # close zip
       $zip-&gt;close();
  
       # send the file to the browser as a download
       ob_start();
       $strFile = file_get_contents($tmp_file);         
       header('Content-disposition: attachment; filename=DOC-'.$id_pra.'-'.$url.'.zip');
       header('Content-type: application/zip');
       echo $tmp_file;
       while (ob_get_level()) {
           ob_end_clean();
       }
  
       readfile($tmp_file);
       exit;   
  }
  </code></pre>