2014-02-18 121 views
0

我有下載的PC設備進行下面的代碼下載文件

$file_url_source = "C:/test.xlsx"; 
    $file_url = "C:/test.xlsx"; 
    header('Content-Type: text/json; charset=UTF-8;'); 
    header('Content-Description: File Transfer'); 
    header('Content-Type: application/octet-stream'); 
    header('Content-Disposition: attachment; filename="' . basename($file_url_source)."") . '"'; 
    header('Content-Transfer-Encoding: binary'); 
    header('Expires: 0'); 
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
    header('Pragma: public'); 
    header('Content-Length: ' . filesize($file_url)); 
    ob_clean(); 
    flush(); 
    readfile($file_url); 

但它不工作的移動設備(我只是測試它在Android手機,並下載download.php文件)。我如何讓移動設備下載文件?

+0

你爲什麼內容類型和處置多次設置? – ElefantPhace

+0

@ElefantPhace我只是編輯 – freestyle

回答

2

這就是你需要:

$file_url = "xxxxxx"; 
header('Content-Type: application/force-download'); 
header('Content-Disposition: attachment; filename="' . basename($file_url) .'"'); 
readfile($file_url); 

你的問題是此行

header('Content-Disposition: attachment; filename="' . basename($file_url_source)."") . '"'; 
#                     ^^^^^^^^^ 
#    this is where your problem is, you never put the last " around the file name