我尝试使用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);
我也尝试将它分为几部分进行解压,从.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);
编辑2: 我认为LZW无法正常工作的原因是因为.tar.Z文件的内容看起来像这样:
��3dЀ��0p���a�
H�H��ŋ3j��@�6l�
我尝试过的LZW函数都在它们的词典中使用ASCII字符,这些字符是什么类型的?