简体   繁体   English

如何在Android设备上设置“Content-Disposition:inline;”文件的文件名?

[英]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.

相关问题 Android浏览器拒绝内容处理:内联? - Android browser rejects content-disposition:inline? 如何使用 content-disposition 标头设置下载的 UTF-8 文件名? - How to use the content-disposition header to set a downloaded UTF-8 filename? PHP标头内容 - 处置:附件强制.php文件或内联 - PHP Header Content-Disposition: attachment forces .php file or inline 如何更正Content-Disposition标头中的文件名值? - How to correct filename value in Content-Disposition header? PHP Content-Disposition header:文件名中的特殊字符 - PHP Content-Disposition header: Specialcharacters in the filename PHP - 如何在Content-Disposition中设置完整目录路径? - PHP - How to set full directory path in Content-Disposition? 如何通过Content-Disposition阅读xls文件返回:PHP附件 - How to read xls file return by Content-Disposition: attachment with PHP 从URL检索zip,但使用Content-Disposition文件名标识符保存到本地文件 - Retrieve zip from URL, but save with Content-Disposition filename identifier to local file 内容处置:内联标题不会内嵌显示图像? - Content-disposition:inline header won't show images inline? 即使我使用Content-Disposition:inline,PHP也会强制下载PDF文件 - PHP forces PDF file download even though I'm using Content-Disposition: inline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM