Php 命名下载文件时出现问题

Php 命名下载文件时出现问题,php,Php,我有一些php代码,可以下载一个zip文件……这段代码是从一个名为download\u file.php的文件调用的(我知道,非常原始) 有关职能如下: function download_clientfile() { if ($this->download_file === FALSE) { $this->log->log(sprintf("The download file was not generated."), PEAR_LOG_CRIT);

我有一些php代码,可以下载一个zip文件……这段代码是从一个名为download\u file.php的文件调用的(我知道,非常原始)

有关职能如下:

function download_clientfile() {
    if ($this->download_file === FALSE) {
        $this->log->log(sprintf("The download file was not generated."), PEAR_LOG_CRIT);
        return;
    }

    $fsize = filesize($this->download_file);
    $path_parts = pathinfo($this->download_file);
    $ext = strtolower($path_parts["extension"]);

    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; file='.$path_parts['basename']);
    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($this->download_file));
    ob_clean();
    flush();
    readfile($this->download_file);
    exit;
}


问题:下载的文件是预期的zip文件,但下载的文件名为“download_file.php”

关于如何通过zip文件名下载的任何建议。 谢谢

使用文件名而不是文件:

此外,您可能会遇到使用扩展的浏览器。在这种情况下,可以如下方式调用脚本:

download_file.php?file=myfile.zip
或:


这样,URL以.zip结尾,这会使浏览器误以为它正在下载一个zip文件。

尝试将file=更改为filename=

header('Content-Disposition:attachment;filename='。$path\u parts['basename'])

使用

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

非常感谢。至少在Firefox和Chrome上,改为文件名而不是文件名起了作用。
download_file.php/myfile.zip
header("Content-Disposition: attachment; filename=\"$filename\"");