7

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

Dekel
  • 60,707
  • 10
  • 101
  • 129
Yugal Kishor Bais
  • 199
  • 1
  • 1
  • 8

1 Answers1

18

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.

Dekel
  • 60,707
  • 10
  • 101
  • 129