By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,558 Members | 1,607 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,558 IT Pros & Developers. It's quick & easy.

Serving PDF Problem

P: n/a
I'm still having a problem with the following code, but I can better
describe the symptoms now.

Code:

<?php
$uri = getenv('REQUEST_URI');
$pieces = explode('/',$uri);
$file = $pieces[count($pieces)-1];

header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename=".$file);
readfile('/home/america2/pdfs/'.$file);
?>
The code appears to work perfectly in NN7, but in IE6 it only works when the
user chooses to "Save" the file to the hard drive. If the user chooses to
open the file, Adobe Reader launches, but before a PDF is rendered, the
following error is displayed.

"There was an error opening this document. The file does not exist."

Any suggestions?
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Kubaton Lover" <no****@goawayspam.com> wrote in message
news:vr************@corp.supernews.com...
I'm still having a problem with the following code, but I can better
describe the symptoms now.

Code:

<?php
$uri = getenv('REQUEST_URI');
$pieces = explode('/',$uri);
$file = $pieces[count($pieces)-1];

header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename=".$file);
readfile('/home/america2/pdfs/'.$file);
?>
The code appears to work perfectly in NN7, but in IE6 it only works when the user chooses to "Save" the file to the hard drive. If the user chooses to
open the file, Adobe Reader launches, but before a PDF is rendered, the
following error is displayed.

"There was an error opening this document. The file does not exist."

Any suggestions?


In case anyone else has this problem... the problem is the following line:
header("Content-Disposition: attachment; filename=".$file);

In a previous thread, "R. Rajesh Jeba Anbiah" suggested a website
(http://in2.php.net/header ). That website suggested that I add that line
to fix a "bug" with IE6. I'd have to go back and re-read it to see what it
was trying to fix, but it appears to have caused more problems for me than
corrected.

All seems to be working great now.
Jul 17 '05 #2

P: n/a
"Kubaton Lover" <no****@goawayspam.com> wrote in message news:<vr************@corp.supernews.com>...
"Kubaton Lover" <no****@goawayspam.com> wrote in message
news:vr************@corp.supernews.com... <snip>
In case anyone else has this problem... the problem is the following line:
header("Content-Disposition: attachment; filename=".$file);

In a previous thread, "R. Rajesh Jeba Anbiah" suggested a website
(http://in2.php.net/header ). That website suggested that I add that line
to fix a "bug" with IE6. I'd have to go back and re-read it to see what it
was trying to fix, but it appears to have caused more problems for me than
corrected.


Did you actually read the usernotes there? Is the following note
caused you the problem actually?

<--------------------------------->
15-Oct-2003 12:27
Some browsers out there on the Internet act funny, especially with
Internet Explorer (IE), so this script will help. This is ony an
example for displaying the PDF. You can REM out the code and change
it to make it be a downloadable file instead.

--snip--
<?
$filename=$_REQUEST['PDF_FileName'];
$filepath=$_REQUEST['PDF_FilePath'];

$filesize=filesize($filepath);

header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0,
pre-check=0");

header("Content-Type: application/pdf");
header("Content-Length: ".$filesize);
header("Content-Disposition: inline; filename=$filename");
header("Content-Transfer-Encoding: binary");

//Can't use readfile() due to poor controlling of the file
download.
//(IE have this problems)...
//readfile($filepath);

//use fopen() instead of readfile...
$fp = fopen($filepath, 'rb');
$pdf_buffer = fread($fp, $filesize);
fclose ($fp);

//sleep(1);

print $pdf_buffer;

//Required, to keep IE from running into problems
//when opening the file while downloading or downloading...
//(IE been acting strange lately...)
exit();
?>
--snip--
<--------------------------------->

---
"We live to die; we die to live"
Email: rrjanbiah-at-Y!com
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.