下载强制文件添加下划线"_"下载的文件名


Download force file adds underscore "_" to downloaded filename

这是我下载文件的脚本

问题是,当下载一个文件时,比如文件名是music,文件名被更改为

_var_www_myporject_module_Application_musicdir_music

我不想要

这是我的代码片段

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;
    }
}

修改

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

:

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

使其只显示文件名,而不显示目录名。