473,473 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Serving PDF Problem

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
2 5093
"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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Margaret MacDonald | last post by:
I want to store frequently-used graphic elements in a db and serve them from there rather than from the filesystem. Is there a better/faster way to do that than this? (error checking etc not...
2
by: Thomas W | last post by:
Hi, I'm having some problems serving binary data in a simple CGI-script. I'm setting content-type ( "application/octet-stream" ), content-length and Content-disposition and I think these are...
3
by: -[ CaMeL ]- a55m0nk | last post by:
Hi there i am creating a clan website in ASP and am making a page serving script a link sends a query to the default page and then serves the page by grabbing the HTML from a database that...
0
by: jack | last post by:
I am getting this error on my web server runnint ASP.NET on Windows 2003, it kills the serving web pages. The only way to get the web pages to start serving is to restart the server. I can't find...
21
by: Nicholas Sherlock | last post by:
Hey all, People on my website register to be allowed access to certain downloads. I store these files above the document root so that they can't be accessed by Apache (Only from PHP). I wrote a...
1
by: Ben | last post by:
Hi there, Perhaps someone can help me. For some reason, when my Python script runs and loads an HTML page in a new browser window at the local host (desktop), the links to my stylesheet and all...
2
by: Jim Stools | last post by:
Server 2000 IIS 5 The server stopped serving pages on all the web sites: The Following error message: The page cannot be found HTTP 404 - File not found Internet Information Services
30
by: abracad_1999 | last post by:
Is it possible to serve valid xhtml with php? xhtml requires the 1st line: <?xml version="1.0" encoding="iso-8859-1"?> But php interprets the opening <? as a php statement. If I try to echo...
12
by: -Lost | last post by:
In Firefox and Safari for example, if I serve my XHTML documents as application/xml or xhtml+xml they only display the top inch or so of the document. In Opera it says "object has been blocked."...
3
by: Sander Tekelenburg | last post by:
Situation: I store news articles as individual PHP files. Each file contains HTML and now and then some embedded PHP snippets. Serving those news articles on the Web works fine, through...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.