php : abount Content-Disposition header


php : abount Content-Disposition header

服务器中名为"hashed.png"的文件。我可以像一样提出要求

"http://server_name/hashed.png"

但当我上传到服务器时,它的原名是"hello.png"(它的关系在数据库中),当我请求那个url并下载它时,它被命名为"hashed.png"。我想显示它"hello.png"

总结:我想做这个

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

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

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

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

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

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

传递内容