2
function uncompress($srcName, $dstName) {
    $sfp = gzopen($srcName, "rb");
    $dstName = str_replace('.gz', '', $dstName);
    $fp = fopen($dstName, "w");

        fseek($FileOpen, -4, SEEK_END);
        $buf = fread($FileOpen, 4);
        $GZFileSize = end(unpack("V", $buf));

    while ($string = gzread($sfp, $GZFileSize)) {
        fwrite($fp, $string, strlen($string));
    }
    gzclose($sfp);
    fclose($fp);
}

I use this code for uncompressing but It does not work and I get following error:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@example.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

  • Check your error log for more details about the 500 error. Probably you ran out of memory, but could be some other problem. The log will have details - what you see in the browser is deliberately useless to prevent leaking internal configuration details. – Marc B Jun 29 '12 at 18:48

3 Answers3

3

This function looks sketchy. It seems you're reimplementing stream_copy_to_stream() in userland. Forget about buffers and simply use the native stuff.

function uncompress($srcName, $dstName)
{
    $src = gzopen($srcName, 'rb');
    $dst = fopen($dstName, 'wb');

    stream_copy_to_stream($src, $dst);

    gzclose($src);
    fclose($dst);
}

Come to think of it, you could probably even use copy()

function uncompress($srcName, $dstName)
{
    copy('compress.zlib://' . $srcName, $dstName);
}
Josh Davis
  • 28,400
  • 5
  • 52
  • 67
2

I changed my function to this and my problem was solved :

function uncompress($srcName, $dstName) {
        $sfp = gzopen($srcName, "rb");
        $dstName = str_replace('.gz', '', $dstName);
        $fp = fopen($dstName, "w");


            $GZFileSize = filesize($srcName);


        while ($string = gzread($sfp, $GZFileSize)) {
            fwrite($fp, $string, strlen($string));
        }
        gzclose($sfp);
        fclose($fp);
    }
1

This should help you see the error messages. Either it will displayed on the screen or will be printed into the txt file, although the directory must be writable by php.

<?php //top of script
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', 'errors.txt');
goat
  • 31,486
  • 7
  • 73
  • 96