0

basically we currently generate a csv file and push it too the clients browser to download, so no physical files are involved or stored as these are reports that always change. These have become quite large in some places and I need to reduce the speed and size of the downloads to clients.

I decided to go the zip root and got the below test script working fine, however i am still having to generate the zip file physically and then later delete it, obviously there is a speed factor here as I am writing and reading the file, when I only need to push the zip files contents to the browser.

is there no way to create a stream with the ziplib?

<?php


//report
$reportFilename = 'report';
$data = '005,"756607       ","WED","L","TEST UITENHAGE CBD F NFD"
        005,"756608       ","MON","L","TEST SUMMERSTRAND NNB   "
        005,"756634       ","WED","L","TEST UITENHAGE PENFORD F"
        005,"756776       ","MON","L","TEST WALKER DRIVE FOOD  "
        005,"756858       ","MON","C","TEST R ADAMI&SONS C C  "
        005,"801002       ","MON","L","TESTMOFFET NNB "
        005,"CP00270      ","WED","L","TEST  WALMER P FNF       "
        ';   //dummy data

// populate fake data...
$reportData = $data.$data.$data.$data.$data.$data.$data.$data.$data.$data.$data; 

//make unique so no clashing occurs
$zipFilename = '_temp_'.microtime().$zipFilename;

//zip data
$zip = new ZipArchive();
$zip->open($zipFilename, ZIPARCHIVE::CREATE);
$zip->addFromString($reportFilename.'.csv' , $reportData);    //add report
$zip->close();

$zipData = file_get_contents($zipFilename);
$zipSize = filesize($zipFilename);
unlink($zipFilename);

header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=\"".$reportFilename.".zip\"");
header('Content-Transfer-Encoding: binary');
header("Content-Type: application/zip");
echo $zipData;

?>
4

0 回答 0