解压缩

时间:2016-06-08 07:41:46

标签: php archive tar

我正在尝试使用tar(以及php)创建ajax存档,当存档大于时,解包后会出现此错误:"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_*个功能,但它没用。

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

1 个答案:

答案 0 :(得分:0)

看来你的标题有问题 试试这些

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

}
相关问题