[英]How to set a filename for “Content-Disposition: inline;” file on android device?
Greeting. 问候语。
There's a following set of header I use to process file being opened inline in browser window(usually it is PDF): 我使用以下一组标题来处理在浏览器窗口中内联打开的文件(通常是PDF):
header("Content-Type: " . $mime[$ext]);
header("Content-Disposition: inline; filename=" . $path_parts["basename"]);
header("Content-length: $fsize");
header("Cache-control: private");
This code is placed in download.php file to achieve extra steps being done before file is actually thrown to client. 此代码放在download.php文件中,以实现在将文件实际抛出到客户端之前执行的额外步骤。 Where uri to file is set as get variable like this:
将uri to file设置为get变量,如下所示:
http://sitedotcom/download.php?=file=path-to-file.pdf
And the problem is the following. 问题是以下几点。 Desktop opens file inline in browser window, but android device downloads it and set filename to download.php instead of path-to-file.pdf.
桌面在浏览器窗口中打开文件,但是android设备会下载并将文件名设置为download.php而不是path-to-file.pdf。 This causes misunderstanding and am looking for help.
这会引起误解,我正在寻求帮助。
Is there a way to setup header somehow so that file gets a correct name? 有没有办法以某种方式设置标题,以便文件获得正确的名称?
Maybe you can use the apache module rewrite like this: 也许你可以像这样使用apache模块重写:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^pdf/([^/\.]+)$ download.php?file=$1 [L]
</IfModule>
The user will ask for: 用户会要求:
http://sitedotcom/pdf/path-to-file.pdf
and the PHP will handle the URL 并且PHP将处理URL
http://sitedotcom/download.php?file=path-to-file.pdf
So when the file will be saved it will be under "path-to-file.pdf" 因此,当文件将被保存时,它将位于“path-to-file.pdf”下
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.