PharData extractTo method failed to extract .tar.gz on linux environment

邮差的信 提交于 2020-01-04 04:11:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!