Phar unable to extract a file

465 Views Asked by At

I`m trying to extract a tar file using Phar Classe, but is returning the following error:

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);
}

When I download this file, I can open and extract normally using Winrar.

The file is generated by an API from Sentinel Hub (https://services.sentinel-hub.com/api/v1/process)

Any ideas why is this happening?

Thanks

1

There are 1 best solutions below

0
On

I got the same message from an homemade tar program building a tar file. I could not untar it with the PHAR class. The problem was the CRC field, wrote on the last line of the tar file, that was miscalculated by the program that made originely that tar file.