2011-04-16 76 views
0

我正在使用腳本下載視頻,但需要大量時間下載。有任何流程或其他腳本可以幫助我嗎?如何通過php腳本下載mp4視頻時提高下載速度

// set headers 
header("Pragma: public"); 
header("Expires: 0"); 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("Cache-Control: public"); 
header("Content-Description: File Transfer"); 
header("Content-Type: $mtype"); 
header("Content-Disposition: attachment; filename=\"$asfname\""); 
header("Content-Transfer-Encoding: binary"); 
header("Content-Length: " . $fsize); 

// download 
// @readfile($file_path); 
$file = @fopen($file_path,"rb"); 
if ($file) { 
    while(!feof($file)) { 

    print(fread($file, 1024*100)); 
    flush(); 
    if (connection_status()!=0) { 
     @fclose($file); 
     die(); 
    } 
    } 
    @fclose($file); 
} 

回答

1

使用readfile()功能(如你原本)將允許您直接從文件後臺輸出,而不是使用分塊循環和印刷爲你做。那麼爲什麼你選擇做這個塊循環?

0

如上,readfile()是一種方式。

另一種更優選的方法取決於您的網絡服務器。 NginX,Lighttpd,還有一個Apache模塊,允許您將帶有文件路徑/名稱的頭傳遞給服務器,並且它將直接從服務器本身發送文件,因此不需要使用PHP資源來執行此操作。如果這是不可能的,那麼readfile()是你可能擁有的最好的 - 如果你不能給某人一個直接的URL來下載它。