【问题标题】:How to set a filename for "Content-Disposition: inline;" file on android device?如何为“Content-Disposition: inline;”设置文件名安卓设备上的文件?
【发布时间】:2014-01-25 02:15:36
【问题描述】:

问候。

我使用以下一组标题来处理在浏览器窗口中内联打开的文件(通常是 PDF):

header("Content-Type: " . $mime[$ext]);
header("Content-Disposition: inline; filename=" . $path_parts["basename"]);
header("Content-length: $fsize");
header("Cache-control: private");

此代码放置在 download.php 文件中,以实现在文件实际被抛出给客户端之前完成的额外步骤。其中 uri to file 设置为 get 变量,如下所示:

http://sitedotcom/download.php?=file=path-to-file.pdf

问题如下。桌面在浏览器窗口中打开文件内联,但 android 设备下载它并将文件名设置为 download.php 而不是 path-to-file.pdf。这会引起误解,正在寻求帮助。

有没有办法以某种方式设置标题以便文件获得正确的名称?

【问题讨论】:

    标签: php android download http-headers content-disposition


    【解决方案1】:

    也许你可以像这样使用 apache 模块重写:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^pdf/([^/\.]+)$ download.php?file=$1 [L]
    </IfModule>
    

    用户会要求:

    http://sitedotcom/pdf/path-to-file.pdf
    

    PHP 将处理 URL

    http://sitedotcom/download.php?file=path-to-file.pdf
    

    所以当文件被保存时,它将位于“path-to-file.pdf”下

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-07
      • 2019-12-29
      • 1970-01-01
      • 2016-08-25
      • 2013-09-09
      • 2015-01-29
      相关资源
      最近更新 更多