Und*_*ech 13 php compression lzw
我曾尝试使用Zlib解压缩文件,但它只是说"数据错误"并给了我一个空文件.
这是我试过的代码:
// Open a new temp file to write new file to
$tempFile = fopen("tempFile", "w");
// Make sure tempFile is empty
ftruncate($tempFile, 0);
// Write new decompressed file
fwrite($tempFile, zlib_decode(file_get_contents($path))); // $path = absolute path to data.tar.Z
// close temp file
fclose($tempFile);
Run Code Online (Sandbox Code Playgroud)
我也尝试过将其解压缩,从.tar.Z到.tar再到一个文件.我尝试使用lzw函数来取消.Z,但我无法使它工作.有没有办法做到这一点?
编辑:
这是我尝试过的一些代码.只是为了确保它file_get_contents正常工作.我仍然收到"数据错误".
$tempFile = fopen("tempFile.tar", "w");
// Make sure tempFile is empty
ftruncate($tempFile, 0);
// Write new decompressed file
$contents = file_get_contents($path);
if ($contents) {
fwrite($tempFile, gzuncompress($contents));
}
// close temp file
fclose($tempFile);
Run Code Online (Sandbox Code Playgroud)
EDIT2:我认为LZW无法正常工作的原因是因为.tar.Z文件的内容如下所示:
??3d???0p???a?
H?H???3j??@?6l?
Run Code Online (Sandbox Code Playgroud)
我试过的LZW函数都在字典中使用ASCII字符.这些是什么角色?
那么您想使用 PHP本地解压缩 taz 文件吗?尝试一下我的新扩展!
lzw_decompress_file('3240_05_1948-1998.tar.Z', '3240_05_1948-1998.tar');
$archive = new PharData('/tmp/3240_05_1948-1998.tar');
mkdir('unpacked');
$archive->extractTo('unpacked');
Run Code Online (Sandbox Code Playgroud)
另请注意,zlib 函数不起作用的原因是您需要 LZW 压缩,而不是 gzip 压缩。