【问题标题】:The tar archive is corrupt when unpacking解压时 tar 存档损坏
【发布时间】:2016-10-08 08:25:40
【问题描述】:

我正在尝试使用php(和ajax)创建一个tar 存档,并且在解压缩时出现此错误:"The tar archive is corrupt" 当存档大于2GB 时。当存档小于 2GB 时一切正常。

这是我的代码:

function download_files() {
   set_time_limit(0);

   ob_start( );
   $filename = "download.tar";
   $path = "temp/$filename";

   $files = '';
   foreach($_GET['dfile'] as $file){
       $files .= "$file ";
   }

   $cd_dir = FCPATH.'uploads';
   system("cd $cd_dir && tar -cf $path $files");

   header("Content-Transfer-Encoding: Binary");
   header("Content-Length: ".filesize(FCPATH."uploads/$path"));
   header('Content-Type: application/octet-stream');
   header('Content-Disposition: attachment; filename="'.$filename.'"');

   ob_end_flush();
   readfile(FCPATH."uploads/$path");
   unlink(FCPATH."uploads/$path");
}

我尝试删除 ob_* 函数,但没用。

任何帮助请 :) 提前致谢。

【问题讨论】:

  • tar -cf $path $files" ...这似乎是系统问题而不是编程问题。
  • “我尝试删除 ob* 函数,但它没用”_ - 它们一开始就相当没用......当没有真正的输出并且只有标题时输出缓冲设置,只是不必要的。 / 至于问题,您是否尝试过在文本或十六进制编辑器中打开其中一个损坏的 >2GB 文件,以检查它们是否可能包含任何错误消息(来自 PHP 或命令行 tar 调用)?跨度>
  • 我试过了,没有错误信息

标签: php archive tar


【解决方案1】:

您的标题似乎有问题 试试这些

header("Content-Type: application/x-gzip-compressed");
header("Content-Disposition: attachment; filename=$filename");

试试这个

function downloadTar($filename, $path)
{
    $path_file = $path."/".$filename ;
    if(file_exists($path_file))
    {
        header("Content-Type: application/x-gzip-compressed");
        header("Content-Disposition: attachment; filename=$filename");
        ob_clean();
        flush();
        readfile("$path_file"); 
        exit;
    }   

}

【讨论】:

    猜你喜欢
    • 2016-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-23
    • 2019-07-26
    • 2019-04-18
    • 1970-01-01
    • 2021-04-07
    相关资源
    最近更新 更多