2013-07-10 67 views
0

我有一個腳本,允許用戶下載文件大小> 250MB的文件。當文件大小是< 100MB時,它是可下載的。但不是文件> 250 MB。如何在php下載大文件(> 250 MB)?

I have changed the setting in php.ini: 
memory_limit = 12800M 
post_max_size = 8000M 
upload_max_filesize = 2000M 
max_execution_time = 512000 

但仍然不可行。如何使它可以下載大於250MB的文件?

更新:代碼下載zip文件

ini_set('max_execution_time', 512000); 

$file_folder = "image/data/"; // folder to load files 

$zip = new ZipArchive();   // Load zip library 
$zip_name = "image.zip";   // Zip name 
if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE){  // Opening zip file to load files 
    echo "* Sorry ZIP creation failed at this time<br/>"; 
} 

$dir = opendir ("image/data"); 
$counter = 0; 
while (false !== ($file = readdir($dir))) 
{ 
    if($file == '.' || $file == '..') 
    { }else 
    { 
     $zip->addFile($file_folder.$file, $file); 
    } 
} 

$zip->close(); 

// push to download the zip 
header('Content-type: application/zip'); 
header('Content-Disposition: attachment; filename="'.$zip_name.'"'); 
header('Content-Length: ' . filesize($zip_name)); 
readfile($zip_name); 
// remove zip file is exists in temp path 
unlink($zip_name); 
+2

通過使用Apache的mod_xsendfile:https://tn123.org/mod_xsendfile/ – Twisted1919

+0

您可以將文件分割成更小的部分,並下載 – senthilbp

+0

嗯,我不能BCOS我是從現有的文件夾中讀取數據,並下載它的zip文件夾 – Verlee

回答

0

Ok..so現在我可以得到我要下載的文件。但是,一旦我想提取壓縮文件,給出錯誤消息,說:存檔是未知的格式或損壞。我檢查原始文件夾中的壓縮文件的副本n嘗試提取,它工作正常。在提取數據時沒有問題。以下是腳本:

set_time_limit(0); 
$file_folder = "image/data/"; 

$zip = new ZipArchive(); // Load zip library 
$zip_name = "image.zip";    // Zip name 
if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE){  // Opening zip file to load files 
    echo "* Sorry ZIP creation failed at this time<br/>"; 
} 

$dir = opendir ("image/data"); 
$counter = 0; 
while (false !== ($file = readdir($dir))) 
{ 
    if($file == '.' || $file == '..') 
    { }else 
    { 
     $zip->addFile($file_folder.$file, $file); 
    } 
} 

$zip->close(); 
if(file_exists($zip_name)){ 

    // set headers push to download the zip 
    header("Pragma: public"); 
    header("Expires: 0"); 
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
    header("Cache-Control: public"); 
    header('Content-type: application/zip'); 
    header("Content-Transfer-Encoding: Binary"); 
    header('Content-Disposition: attachment; filename="'.$zip_name.'"'); 
    header("Content-Length: ".filesize($zip_name)); 

    //readfile($zip_name); 
    // remove zip file is exists in temp path 
    //unlink($zip_name); 

    $fp = @fopen($zip_name, "rb"); 
    if ($fp) { 
    while(!feof($fp)) { 
     echo fread($fp, 1024); 
     flush(); // this is essential for large downloads 
     if (connection_status()!=0) { 
      @fclose($zip_name); 
      die(); 
     } 
    } 
    @fclose($zip_name); 
    } 
    unlink($zip_name); 
} 

我檢索的文件大小也是正確的。問題是什麼?

相關問題