Hi, I also had some troubles when managing PDF files.
Let me tell you that I'm not a PHP programmer (yet!), but I think that the LOGIC is more important than the Language.
this is what I wanted:
1: The Browser must prompt the "save as" dialog when I clik on the "Download link"
2: The file must be viewed directly on the browser when I clik on the "view link"
The trick is as follows...
The IE doesn't care for the headers (content-type: xxx) It only cares for this header (content-disposition: attachment) because It manage the file acording with with the extension AND the SCRIPT URL. Netscape and others, in the other hand, they do need the complete headers. In a few words...
if ($ENV{HTTP_USER_AGENT} =~ /MSIE/)
{
$mHeader = "Content-Disposition: attachment;\n\n"; #--> This is the header for IE
}
else
{
$mHeader = "Content-type: application/octet-stream;\nContent-Disposition: attachment; filename=\"MyFile.pdf\"\n\n"; #--> And this one for Netscape and others
}
after that you must create a script named exactly like the one you are trying to download (MyFile.pdf) and it must contain the code for printing the pdf file to the user. (Note that the script must have the same extension as the download file, in this case PDF, so, you must configure your WebServer to treat the PDF extension as a CGI Script)
and finally create the link like this:
<a href="//my_site.com/MyFile.pdf" target="new"> (Dont forget to include the TARGET="new" otherwise it will not work!!)
the reason is because IE takes the filename from the URL navigation bar ando that's also the reason why the CGI Script should be equal as the download file.
- For the second example....
this are the headers you need:
if ($ENV{HTTP_USER_AGENT} =~ /MSIE/)
{
$mHeader='Content-type: application/pdf
Content-disposition: inline;
';
}
else
{
$mHeader='Content-type: application/pdf
Content-disposition: inline; filename="'.$mDirTmp.'/'.$mTmpNames.'.pdf"
';
}
In this case you can omit target="_new" on the link, IE should display the content of the file in the same window and Netscape opens another window to display the file.
That's IT!
Please excuse my english, it's not good, buy I tried to do my best 🙂
Any questions? Feel free to write to my e-mail vortiz@vera.net
By the way the credit is not mine, a friend of mine gave me this solition, her name is Vanessa JalÃl vanessa@aix.ver.ucc.mx
Write to her if somthing goes wrong!! just kidding.
Chears!
Valentin Ortiz Ferretiz.
Veracrúz, Mexico.