修改通过 mod_xsendfile 下载的文件的文件名

Modify filename for file downloaded via mod_xsendfile

我正在使用 mod_xsendfile 在网页上下载/显示文件。它工作正常,我只是想知道是否有任何方法可以在发送文件之前修改文件名?

我想我必须 copy/rename 暂时管理该文件?这对于大文件可能不可行(由于超时,或至少等待时间)。

我问的原因是我有公开共享的文件,这些文件以共享文件名的用户为前缀 - 所以而不是 videofile.mp4 它会说 username__videofile.mp4- 不是很大交易,这不像下载器不知道谁共享了文件,如果文件名只是原始文件名,它只会使它稍微容易一些。

我猜临时 copy/rename 是唯一的方法吗?

无需进行临时复制或重命名。 只需这样做:

header("X-Sendfile: {$sourceFilename}");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"{$outFilename}\"");

$outFilename 设置为您想要的任何名称。 它适用于 Apache 2.4.9。