使用 X-Sendfile 下载的文件文件名


Downloaded filename of file using X-Sendfile

我使用 X-Sendfile 发送文件而不是 readfile。处理此内容的脚本名为 download.php 并包含以下内容:

$video_file = '/path/to/file/file.mp4';
header('X-Sendfile: '.$video_file);
header('Content-Type: video/mp4');
header('Content-Disposition: attachment; file='"file.mp4'"');
exit();

但问题是下载的文件总是被命名为"download.php"(155Mb),我想下载它命名为file.mp4。我尝试了几件事,例如:

header('Content-Disposition: attachment; file="file.mp4"');
header('Content-Disposition: attachment; file=file.mp4');

和所有其他可能性,但仍将文件下载为下载.php。

我的htaccess文件包含: XSendFile On

您发送的标头不正确。文件名属性称为 filename ,而不是name

header('Content-Disposition: attachment; filename="file.mp4"');

有关标头的详细说明,请参阅 RFC2616。