2012-02-06 95 views
0

我在指向視頻文件(mp4)的頁面上有一個<a href>鏈接。當訪問者點擊鏈接時,視頻文件將在瀏覽器窗口中打開。沒有右鍵點擊下載文件

如果你想下載的文件,你要「右鍵」,然後在「鏈接另存爲...」

我想要的,這樣在一個單一的點擊文件將下載(讓我不必右鍵點擊)。

編輯:這裏有什麼問題?

<?php 
    header('Content-Description: File Transfer'); 
    header('Content-Type: video/mp4'); 
    header('Content-Disposition: attachment; filename=file'); 
    header('Content-Transfer-Encoding: binary'); 
    header('Expires: 0'); 
    header('Cache-Control: must-revalidate'); 
    header('Pragma: public'); 
    header('Content-Length: ' . filesize($file)); 
    ob_clean(); 
    flush(); 
    readfile($file); 
    exit; 
?> 

回答

4

Content-Disposition header設置爲attachment。例如:

Content-Disposition: attachment; filename=lolcats42.mp4 
+0

我還有一個問題,文件大小是0字節,它不起作用。 源代碼在編輯 – Dudu 2012-02-07 18:46:07

+0

[提出新問題。](http://stackoverflow.com/questions/ask) – 2012-02-07 18:58:20