note 106528 added to function.ziparchive-statindex
| From: | Anonymous at osu1 dot php dot net | Date: | Wed, 16 Nov 2011 16:20:27 +0000 |
| Subject: | note 106528 added to function.ziparchive-statindex | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-184524@lists.php.net to get a copy of this message | ||
The CRC returned from this method is a signed number and so can be negative. This isn't how
most CRC's are represented and so can cause problems. Another thing to know is that the
standerd CRC algorithm used for zip files is CRC32b.
So to put this together lets say that you wanted to extract the first file from a zip and then
compare the original CRC with the CRC for the extracted file this is what you would need to do.
(proper error checking is omitted for simplicity).
$zip = new ZipArchive();
$zip->open("myZip.zip");
$stat = $zip->statIndex( 0 );
$name = $stat['name'];
$oldCrc = $stat['crc'];
$zip->extractTo("myPath", $name);
$newCrc = hexdec(hash_file("crc32b", "myPath/" . $name));
// Have to test both cases as the unsigned CRC from within the zip might appear negative as a
signed int.
if($newCrc !== $oldCrc && ($oldCrc + 4294967296) !== $newCrc) {
echo "The files don't match!";
}
----
Server IP: 69.147.83.197
Probable Submitter: 195.10.250.233
----
Manual Page -- http://www.php.net/manual/en/function.ziparchive-statindex.php
Edit -- https://master.php.net/note/edit/106528
Del: integrated -- https://master.php.net/note/delete/106528/integrated
Del: useless -- https://master.php.net/note/delete/106528/useless
Del: bad code -- https://master.php.net/note/delete/106528/bad+code
Del: spam -- https://master.php.net/note/delete/106528/spam
Del: non-english -- https://master.php.net/note/delete/106528/non-english
Del: in docs -- https://master.php.net/note/delete/106528/in+docs
Del: other reasons-- https://master.php.net/note/delete/106528
Reject -- https://master.php.net/note/reject/106528
Search -- https://master.php.net/manage/user-notes.php