【发布时间】:2021-03-04 22:23:47
【问题描述】:
我正在尝试使用 Phar Classe 提取 tar 文件,但返回以下错误:
UnexpectedValueException Object ( [message:protected] => phar error: "/home/filelocation/file.tar" is a corrupted tar file (truncated) [string:Exception:private] => [code:protected] => 0 [file:protected] => /home/inplan/public_html/uncompress_files.php [line:protected] => 89 [trace:Exception:private] => Array ( [0] => Array ( [file] => /home/inplan/public_html/uncompress_files.php [line] => 89 [function] => __construct [class] => PharData [type] => -> [args] => Array ( [0] => uploads/maps/true_color_4.tar ) ) ) [previous:Exception:private] => )
PHP:
try {
$phar = new PharData('uploads/maps/true_color_'.$id_technical_report.'.tar');
$phar2 = $phar->convertToExecutable (Phar::TAR,Phar::NONE);
$phar2->extractTo('uploads/maps/');
} catch (Exception $e) {
print_r($e);
}
当我下载这个文件时,我可以使用 Winrar 正常打开和解压。
该文件由 Sentinel Hub (https://services.sentinel-hub.com/api/v1/process) 的 API 生成
任何想法为什么会发生这种情况?
谢谢
【问题讨论】:
-
我认为错误信息非常明确:"/home/filelocation/file.tar" 是损坏的 tar 文件(截断)。请说明您为解决此问题所做的工作,以便我们进一步为您提供帮助。
-
实际上文件没有损坏。我可以下载并解压。
-
从你的代码来看,你也上传了。你确定上传顺利吗?你比较过校验和吗?有时,如果未在 FTP 会话上设置正确的传输模式,文件可能会损坏,仅举一个可能发生的示例。
-
该文件是在服务器中创建并返回 API,使用:file_put_contents('uploads/maps/true_color_'.$id_technical_report.'.tar',$response);我下载了完全相同的文件,在 Winrar 中它工作正常。
-
它有多大?您是否在服务器日志中收到任何其他错误/警告?