I have a website which is developed in PHP and hosted in amazon server. PDF files that are uploaded in server are not opening for view in chrome browser but this pdf file is opening in other browser (internet explorer) for viewing. In chrome it is downloaded. I want this pdf to be open for viewing. code for link is
<a href="<?php echo $filename;?>" target="_blank"><?php echo $data['File_Label'];?></a>
URL: Please click here
But below file is opening for viewing in chrome Please check this
If you want the browser to treat the file as pdf you should let him know that his file is a pdf. The way to do so is to send the relevant header:
Content-type: application/pdf
The current header that is sent by s3
is:
Content-type: application/octet-stream
Since you upload the files to s3 - you can either set the correct mime-type for the file during uploading or afterward, using some of the s3 tools (for example s3cmd for windows).
According to the link to the documentation you provided, the putObjectFile
function is deprecated, but this is the definition:
putObjectFile (string $file, string $bucket, string $uri, [constant $acl = S3::ACL_PRIVATE], [array $metaHeaders = array()], [string $contentType = null])
As you can see - the last parameter is contentType
- so you can set it to application/pdf
when uploading the file.
This will set the correct header when downloading.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With