title: Can't open zip file error on ubuntu server
body: <p>I have to download multiple csv file at once. So, I create zip file and put all of the csv files into that zip file. Everything is work and I can download my zip file and can open on my localhost. And I used windows OS.</p>
  
  <p>Here is my code from <code>export_csv.php</code>.</p>
  
  <pre><code>    for($i=0; $i&lt;$len; $i++) {
          $user_id = $array[$i];
  
          #get user name 
          $name = "...";
  
          #get all day from selected month with holidays
          $day_of_month_arr = allDay_of_month($year,$month); 
  
          #get user datetime
  
          #prepare start and finish time with holidays and weekend
          $result_arr = time_format($result, $day_of_month_arr);
  
          #prepare data as csv format to export as csv
          $exp = export($result_arr);
  
          #put each user csv file into 'Report.zip'
          #archive all csv file as zip and force download that zip file
          $zipname = 'Report.zip';
          $zip = new ZipArchive;
          $zip-&gt;open($zipname, ZipArchive::CREATE);
          $f = fopen('php://memory', 'w');
          $file_name = $name."-".$user_id.".csv";
          foreach ($exp as $arr) {
              fputcsv($f,$arr);
          }
          rewind($f);
          $zip-&gt;addFromString($file_name, stream_get_contents($f));
          //close the file
          fclose($f);
  
      }
  
      $zip-&gt;close();
      header('Content-Type: application/zip');
      header('Content-disposition: attachment; filename='.$zipname);
      header('Content-Length: ' . filesize($zipname));
      readfile($zipname);
  
      // remove the zip archive
      unlink($zipname);
  
      function export() {.......}
      function time_format() {........}
      function allDay_of_month() {......}
  </code></pre>
  
  <p>So, I upload that script <code>export_csv.php</code> to my ubuntu server(production server). And when I try to download this file from production server, I can download the file but can't open this zip file anymore. It shows <code>"......\Report.zip" is invalid"</code>.</p>
  
  <p>When I check whats wrong in <code>php_error_logs</code>, I found this following problems.</p>
  
  <pre><code>[12-Oct-2016 04:09:43 Europe/Berlin] PHP Warning:  main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
  [12-Oct-2016 04:09:43 Europe/Berlin] PHP Warning:  main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
  [12-Oct-2016 04:09:43 Europe/Berlin] PHP Warning:  main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
  [12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning:  main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
  [12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning:  main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
  [12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning:  main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
  [12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning:  main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
  [12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning:  main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
  [12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning:  main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
  [12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning:  main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
  [12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning:  main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
  [12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning:  main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
  [12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning:  main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
  [12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning:  main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
  [12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning:  main(): Cannot destroy the zip context in /opt/lampp/htdocs/project/export_csv.php on line 48
  [12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning:  ZipArchive::close(): Failure to create temporary file: Permission denied in /opt/lampp/htdocs/project/export_csv.php on line 62
  [12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning:  filesize(): stat failed for Report.zip in /opt/lampp/htdocs/project/export_csv.php on line 65
  [12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning:  readfile(Report.zip): failed to open stream: No such file or directory in /opt/lampp/htdocs/project/export_csv.php on line 66
  [12-Oct-2016 04:09:44 Europe/Berlin] PHP Warning:  unlink(Report.zip): No such file or directory in /opt/lampp/htdocs/project/export_csv.php on line 69
  </code></pre>
  
  <p>I think this error is permission problem. But I am newbie in ubuntu OS and so, I don't know how to solve it. </p>
  
  <p>I'm very appreciate for any help.</p>
  
  <p><strong>Update</strong></p>
  
  <p>I add the exact error when I try to download and open zip file from server.</p>