2

これはファイルをダウンロードするための私のスクリプトです

問題は、ファイルをダウンロードするときに、ファイル名が音楽であると言うと、ファイル名が次のように変更されることです。

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

1 に答える 1

2

これを変える

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

に :

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

ディレクトリ名ではなく、ファイル名のみを表示するようにします。

于 2013-03-07T09:42:01.447 に答える