Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Rob Sa
Added: Sep 10, 2019 7:26 AM
Views: 3
Tags: no tags
  1.     $filename = strtoupper($cap_type) . "-Deals";
  2.  
  3.     $zipfile = tempnam("tmp", "zip");
  4.     $zip = new ZipArchive();
  5.     $zip->open($zipfile, ZipArchive::OVERWRITE);
  6.  
  7.     // create a temporary file
  8.     $stream = fopen("php://temp/maxmemory:$php_memory", 'w');
  9.     if($stream === false) {
  10.         die('Failed to create temporary file');
  11.     }
  12.  
  13.         // CSV headers
  14.         fputcsv($stream, $headers[$cap_type]);
  15.  
  16.  $zip->addFromString($filename . ".csv", stream_get_contents($stream, -1, 0) );
  17.         fclose($stream);
  18.     $zip->close();
  19.  
  20.     header('Content-Type: application/zip');
  21.     header('Content-Disposition: attachment; filename="' . $filename . '.zip"');
  22.     header('Content-Length: ' . filesize($zipfile));
  23.  
  24.     readfile($zipfile);
  25.     unlink($zipfile);
  26.     exit;