Is there a way to determine if the gz file is corrupted in PHP?
I am currently using http://www.php.net/manual/de/function.gzread.php#110078 to determine the file size and read the entire * file through
$zd = gzopen ( $file, "r" );
$contents = gzread ( $zd, $fzip_size );
gzclose ( $zd );
Unfortunately, some gz files are corrupt, and the last 4 bytes do not represent the actual length of the gz file. While the number is negative, I can say that something is wrong, but sometimes it is positive (and very large), which leads to an error from memory. How can I check in advance if the file is damaged?
- I read the whole file because I did not find a working path for reading the file line by line, not knowing the size of the longest line, which led (in some cases) to lines that were not completed.
source
share