Hi everyone,
Im running into some issues with IE dealing with PDF attachments.
The code below will work if the user wants to download a PDF, but if I
change Content-Disposition to attachment and allow them to open the
PDF in the browser, IE says something like filename[1]not found (in my
case the filename will be username.pdf). Does anyone have this
working in IE 5.5 or 6? I read several suggestions on various forums
and would not have been able to get this working at all without the
excellent people helping here.
I was originally using readfile, but for large files it was failing
because of silly limitations set by the ISP. So now I use the method
of reading one 4k 'chunk' at a time which solved that problem. Someone
suggested the public cache setting for IE, but I'm not really sure
what that does. I forgot to mention the ISP is also doing PHP through
CGI, yuck! Thanks for any help.
//Determine the appropriate filename for this user and attempt to send
//to the browser with a header
session_start();
$filename="$DOCUMENT_ROOT/reports/".$HTTP_SESSION_VARS["username"].".pdf";
if(file_exists($filename))
{
$size=filesize("$filename");
Header("Content-Type: application/pdf");
Header("Content-Disposition: inline; filename=$filename");
Header("Content-Length: $size");
header('Cache-Control: public');
$fp=fopen($filename,"rb");
while(!feof($fp)) {
$buffer = fread($fp, 4096);
print $buffer;
} fclose($fp);
}
else
{
print "File Not Found";
}