我有一个用PHP开发并托管在亚马逊服务器上的网站。上传到服务器中的PDF文件不会在Chrome浏览器中打开以供查看,但此pdf文件在其他浏览器(Internet Explorer)中打开以供查看。在Chrome中,它被下载。我希望这个pdf可供查看。链接代码为
<a href="<?php echo $filename;?>" target="_blank"><?php echo $data['File_Label'];?></a>
但是下面的文件正在打开以便在chrome Please check this
中查看答案 0 :(得分:3)
如果您希望浏览器将文件视为pdf,您应该让他知道他的文件是pdf。这样做的方法是发送相关标题:
Content-type: application/pdf
s3
发送的当前标头是:
Contant-type: application/octet-stream
由于您将文件上传到s3 - 您可以在上传期间为文件设置正确的mime类型,或者之后使用某些s3工具(例如,对于Windows使用s3cmd)。
根据您提供的link to the documentation,不推荐使用putObjectFile
函数,但这是定义:
putObjectFile (string $file, string $bucket, string $uri, [constant $acl = S3::ACL_PRIVATE], [array $metaHeaders = array()], [string $contentType = null])
如您所见 - 最后一个参数是contentType
- 因此您可以在上传文件时将其设置为application/pdf
。
这将在下载时设置正确的标题。