note 98441 added to class.ziparchive

From: Date: Tue, 15 Jun 2010 22:17:07 +0000
Subject: note 98441 added to class.ziparchive
Groups: php.notes 
Request: Send a blank email to php-notes+get-170159@lists.php.net to get a copy of this message
Read a file from an archive to a variable. A warning is printed automatically in case of a CRC32 mismatch, which we capture, so we can print our own error message. <?php $zip = new ZipArchive(); if ($zip->open('archive.zip')) { $fp = $zip->getStream('myfile.txt'); //file inside archive if(!$fp) die("Error: can't get stream to zipped file"); $stat = $zip->statName('myfile.txt'); $buf = ""; //file buffer ob_start(); //to capture CRC error message while (!feof($fp)) { $buf .= fread($fp, 2048); //reading more than 2156 bytes seems to disable internal CRC32 verification (bug?) } $s = ob_get_contents(); ob_end_clean(); if(stripos($s, "CRC error") != FALSE){ echo 'CRC32 mismatch, current '; printf("%08X", crc32($buf)); //current CRC echo ', expected '; printf("%08X", $stat['crc']); //expected CRC } fclose($fp); $zip->close(); //Done, unpacked file is stored in $buf } ?> To create a corrupt file, change a byte in a zip file using a hex editor. ---- Server IP: 217.160.235.204 Probable Submitter: 77.64.194.39 ---- Manual Page -- http://www.php.net/manual/en/class.ziparchive.php Edit -- https://master.php.net/note/edit/98441 Del: integrated -- https://master.php.net/note/delete/98441/integrated Del: useless -- https://master.php.net/note/delete/98441/useless Del: bad code -- https://master.php.net/note/delete/98441/bad+code Del: spam -- https://master.php.net/note/delete/98441/spam Del: non-english -- https://master.php.net/note/delete/98441/non-english Del: in docs -- https://master.php.net/note/delete/98441/in+docs Del: other reasons-- https://master.php.net/note/delete/98441 Reject -- https://master.php.net/note/reject/98441 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#170159) next »