2013-03-07 80 views
2

這是我的文件下載下載力文件添加下劃線「_」來下載的文件名

的問題腳本,當下載一個文件,讓說,文件名是音樂,文件名更改爲

_var_www_myporject_module_Application_musicdir_music

我希望DONOT

這是段我的代碼

public function downloadAction() { 
    $filename = $this->params()->fromQuery('filename'); 
    $file = "/var/www/myproject/module/Application/musicDir/$filename"; 

    if ($file) { 
     header("Cache-Control: public"); 
     header("Content-Description: File Download"); 
     header("Content-Disposition: attachment;filename = $file"); 
     header("Content-Type: application/octet-stream"); 
     header("Content-Transfer-Encoding: binary"); 

     readfile($file); 
     exit; 
    } else { 
     exit; 
    } 
} 
+5

在大多數文件系統中,文件名不能包含斜槓。你偶然試圖建議一個「另存爲」目錄?你不能。 – 2013-03-07 09:41:18

回答

2

更改此

header("Content-Disposition: attachment;filename = $file"); 

到:

header("Content-Disposition: attachment;filename = $filename"); 

,使其只顯示文件名,目錄名無關。

+0

我試過了,但現在沒有下載該文件 – 2013-03-07 09:51:09