[H-GEN] Pdf-php puzzle

Michael Anthon michael at anthon.net
Mon Sep 27 19:06:13 EDT 2004


Oops, sent this to clinton instead of the list... let's start the whole 
"Reply-To header munging" argument again

Clinton Roy wrote:

>>      header("Content-type: application/pdf");
>>   
>
> I believe that header name should be Content-Type, not Content-type.
> As to the actual mime type, you might want to try
> application/octet-stream or some such.
>  
>
Yeah, should be Content-Type although I suspect most browsers ignore 
this since my code seems to be riddled with both Content-Type and 
Content-type.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17

>>      header("Content-Disposition: attachment; filename=".$file);
>>   
>
>
>> From a brief google, I think you should have quotes around that 
>> filename:
>
>         header("Content-Disposition: attachment; filename="".$file.'"');
>  
>
Depends... quotes are not always required 
http://www.ietf.org/rfc/rfc2183.txt defines this header and how to use it.

Some code extracted from one of my projects goes like this...

case 'pdf':     $content_type = 'application/pdf'; $attach_type = 
'inline'; break;
.
.
.
header("Content-Type: $content_type");
header(sprintf('Content-Disposition: %s; filename="%s"', $attach_type, 
basename($record['cache_filename'])));

Also, beware using readfile.  I don't recall the exact problem with it 
but I believe it works by reading the complete file into memory then 
writing it out again.  Not good for big files since you can hit the php 
memory limit and also if you are reading across a slow link (say NFS 
mounted files) then the client end can time out and close the connection 
if it receives no data for some time.

Cheers,
Michael






More information about the General mailing list