php - 如何使用 php 提取或解压缩 gzip 文件?

标签 php gzip compression

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

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

我试过这段代码,但这不起作用,我明白了:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, webmaster@domain.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.

最佳答案

试试这个发现here

//This input should be from somewhere else, hard-coded in this example
$file_name = '2013-07-16.dump.gz';

// Raising this value may increase performance
$buffer_size = 4096; // read 4kb at a time
$out_file_name = str_replace('.gz', '', $file_name); 

// Open our files (in binary mode)
$file = gzopen($file_name, 'rb');
$out_file = fopen($out_file_name, 'wb'); 

// Keep repeating until the end of the input file
while (!gzeof($file)) {
    // Read buffer-size bytes
    // Both fwrite and gzread and binary-safe
    fwrite($out_file, gzread($file, $buffer_size));
}

// Files are done, close files
fclose($out_file);
gzclose($file);

关于php - 如何使用 php 提取或解压缩 gzip 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11265914/

相关文章:

PHP-MySQL 使用 Simple HTML Dom 库将 "Array"插入到 foreach 循环中的表中

php - 在 php 中使用 "tee…"作为 sendmail_path 在使用 "-f"-参数时会产生一个额外的文件。

PHP 将数据流传输至 AJAX 调用

c - 使用 zlib 解压 gzip 流

Python3进度条和gzip下载

JavaScript 重定向回引用页面

ios - Objective C 中的 ASC-GZIP 解码

video - 减少具有相同格式的视频大小并减少帧大小

javascript - 未提供 Webpack gzip 压缩包,未压缩包是

python - 7z文件中的随机访问