问题
I would like to extract .tar.gz file into the particular folder. I have used cURL to download the .tar.gz file from MailChimp batch operation. I have used below code to extract tar file.
$phar = new \PharData('upload/test.tar.gz');
$phar->extractTo('upload/',null, true);
It is working on windows environment. But on Linux(Ubuntu), I got below error when to run above code.
Uncaught exception 'PharException' with message 'Extraction from phar "upload/test.tar" failed: Cannot extract ".", internal error'
I have already set default apache user and group permission for upload folder.
sudo chown -R www-data:www-data upload/
PHP Version: 5.6.24
I have attach sample .tar.gz file: http://www.simbanic.com/_projects/test/05c902076e.tar.gz
回答1:
I had the same problem with MailChimp batch response archive. Stupid solution, but it works...
$p = new PharData($tarGzArchive, RecursiveDirectoryIterator::SKIP_DOTS);
$p->convertToData(Phar::ZIP);
$zip = new ZipArchive;
$res = $zip->open($createdZipArchive);
if ($res === TRUE) {
$zip->extractTo($destinationPath);
$zip->close();
}
来源:https://stackoverflow.com/questions/38843938/phardata-extractto-method-failed-to-extract-tar-gz-on-linux-environment