【问题标题】:php : abount Content-Disposition headerphp : 关于 Content-Disposition 标头
【发布时间】:2015-04-05 12:27:11
【问题描述】:

服务器中名为“hashed.png”的文件。我可以要求像

http://server_name/hashed.png

但是当我上传到服务器时它的原始名称是'hello.png'(它的关系在db中)并且当我请求该url并下载它时,它命名为'hashed.png'。我想显示它'hello.png'

总结:我想做这样的事情

  1. 当我上传 'hello.png' 时,服务器将其保存在 'hashed.png' + 保存在 'hello.png'、'hashed.png' 的 db 关系中。在php中,我知道'hashed.png'的原名是'hello.png'。

  2. 当我请求“server.com/hashed.png”时,会显示图像,当我尝试保存时,它的名称会自动填充为“hello.png”

我发现命名为“Content-Disposition”,但是当用户通过图像的直接 url 请求时,我不知道如何运行 php 代码。

【问题讨论】:

    标签: php image content-disposition


    【解决方案1】:

    如果您提供的下载框允许用户使用原始文件名保存图像,您可以使用:

    http://php.net/manual/en/function.header.php#example-4903

    如果您的目标是使用其原始名称以内联方式显示图像,您可能需要使用允许原始文件名请求但从 hashed.png 传递内容的重写规则。

    【讨论】:

      猜你喜欢
      • 2012-02-27
      • 1970-01-01
      • 2011-02-02
      • 2011-09-27
      • 2018-10-30
      • 2017-10-29
      • 1970-01-01
      • 2022-07-06
      相关资源
      最近更新 更多