logic-unit
logic-unit

Reputation: 4313

Download File Types Confusion - application/octet-stream

I'm using this code:

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // some day in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=".$original);
header("Content-Transfer-Encoding: binary");
readfile('/tmp/'.$original);

to output files from my server (EC2) which have been grabbed off S3. This works fine for images and .txt files but PDF and .doc seem to be damaged in some way. They won't open, or if they do the content is garbled.

I'm thinking it must be to do with the content type application/octet-stream? However my knowledge is limited in this area - I've done some reading and trial and error, but I'm no further forward with it.

In S3 the content types are set for all files as application/octet-stream. I'm not sure if this is right either (it's not something I've set when uploading the files)

Any ideas appreciated.

Thanks

Upvotes: 1

Views: 8224

Answers (2)

cloudberryman
cloudberryman

Reputation: 4698

for .doc files you should set application/msword, for .pdf files you should set application/pdf

Upvotes: 3

Olli
Olli

Reputation: 752

<?php
header('Content-type: application/pdf'); // set content type
header('Content-Disposition: attachment; filename="downloaded.pdf"'); // force download
readfile('original.pdf'); // read the content to server
?>

Source: http://php.net/manual/en/function.header.php

Upvotes: 0

Related Questions