note 96038 added to ref.zip

From: Date: Thu, 04 Feb 2010 13:31:34 +0000
Subject: note 96038 added to ref.zip
Groups: php.notes 
Request: Send a blank email to php-notes+get-165656@lists.php.net to get a copy of this message
I had some memory problems with very large files in the zip file. The problem with the provided scripts is, that they write file all data at once using something like this: <?php $fstream = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); file_put_contents($file_name, $fstream ); ?> On a 130MB image this resulted in a "Fatal error: Allowed memory size of ... bytes exhausted" message. I changed that to always write just a maximum of 10kb at once (you may change the size as wanted). <?php // get the file's size $fileSize = zip_entry_filesize($zip_entry); // open the target file $outFile = fopen($file_name,"wb"); while ($fileSize>0) { // read/write only up to 10kb per step $readSize = min($fileSize,10240); // decrease the size of the remaining data to read $fileSize -= $readSize; // get the data $content = zip_entry_read($zip_entry, $readSize); // write the data (if any) if ($content !== false) fwrite($outFile,$content); } fclose($outFile); ?> Cheers ---- Server IP: 92.48.74.199 Probable Submitter: 91.45.165.98 ---- Manual Page -- http://www.php.net/manual/en/ref.zip.php Edit -- https://master.php.net/note/edit/96038 Del: integrated -- https://master.php.net/note/delete/96038/integrated Del: useless -- https://master.php.net/note/delete/96038/useless Del: bad code -- https://master.php.net/note/delete/96038/bad+code Del: spam -- https://master.php.net/note/delete/96038/spam Del: non-english -- https://master.php.net/note/delete/96038/non-english Del: in docs -- https://master.php.net/note/delete/96038/in+docs Del: other reasons-- https://master.php.net/note/delete/96038 Reject -- https://master.php.net/note/reject/96038 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#165656) next »