I am getting a strange error message with the following piece of PHP code (I am not a PHP expert):
if ( $file_loc != NULL ) {
if ( file_exists($file_loc) ) {
printf(" file exists");
$handle = fopen($file_loc, "rb");
$contents = fread($handle, filesize($file_loc));
fclose($handle);
$result = gzdecode($contents);
}
}
I am basically trying to load text content from a gzipped file. I get the following error:
Fatal error: Call to undefined function gzdecode() in ...\sites\MyScripts\fw2.php on line 80
Yet, when I take a look at documentation, it does not seem like I would need to include an extra library, or am I being wrong? How can I solve this issue?
UPDATE
Following another question to check whether this library is installed on my PC, the answer is yes, it is.
From PHP info:
So this is getting more and more confusing...
UPDATE II
I have tried:
<?php
echo phpversion().", ";
if (function_exists("gzdecode")) {
echo "gzdecode OK, ";
} else {
echo "gzdecode no OK, ";
}
if (extension_loaded('zlib')) {
echo "zlib extension loaded ";
} else {
echo "zlib extension not loaded ";
}
?>
and I get:
5.2.17, gzdecode no OK, zlib extension loaded
gzdecode is not available unless PHP is complied with zlib. It will possibly be included in PHP 6, according to some sources. Notice in the manual how nearly all functions have given a PHP version number when it became / is available. Oddly, they don't think it needed to display a warning message.
Try this code (works for me) for gzdecode without checksums:
function gzdecode($data)
{
return gzinflate(substr($data,10,-8));
}
It's not always installed. From the documentation:
Zlib support in PHP is not enabled by default. You will need to configure PHP --with-zlib[=DIR]
The Windows version of PHP has built-in support for this extension. You do not need to load any additional extensions in order to use these functions.
edit: Since this is the accepted answer still, I edited it to add the function suggested as replacement.
function gzdecode($data) {
return gzinflate(substr($data,10,-8));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With