473,769 Members | 2,245 Online
Bytes | Software Development & Data Engineering Community
+ 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=".$fil e);
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 5128
"Kubaton Lover" <no****@goaways pam.com> wrote in message
news:vr******** ****@corp.super news.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=".$fil e);
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=".$fil e);

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****@goaways pam.com> wrote in message news:<vr******* *****@corp.supe rnews.com>...
"Kubaton Lover" <no****@goaways pam.com> wrote in message
news:vr******** ****@corp.super news.com... <snip>
In case anyone else has this problem... the problem is the following line:
header("Content-Disposition: attachment; filename=".$fil e);

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=$_REQ UEST['PDF_FileName'];
$filepath=$_REQ UEST['PDF_FilePath'];

$filesize=files ize($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=$filen ame");
header("Content-Transfer-Encoding: binary");

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

//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
1906
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 shown) The relevant piece of the page: <?php echo '<table><tr><td>
2
2534
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 correct, but the size of the served file/data is different than the source. The read and write the data I'm doing a plain : f = open (..., 'rb') d = f.read(2048)
3
2216
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 refers to the pageID. this works like a peach whenever the page is just HTML e.g. http://www.deathworld.net/camel2.0/default.asp?id=2
0
5063
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 what is causing this. Any Help would be great!!! Event Type: Warning Event Source: W3SVC Event Category: None Event ID: 1012
21
1990
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 file serving script which dumps the correct headers for the download and calls readfile(). I thought everything was going swimmingly until I realized that my webhost has Safe Mode turned on, and the script execution time is limited to 30...
1
3432
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 the images are broken. I did check the HTML file by itself...everything loaded fine ;) Here's my script: -------------------- # File: webbrowser-test.py
2
1686
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
2274
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 this in PHP: <?php echo '<?xml version="1.0" encoding="iso-8859-1"?>'; ?>
12
1981
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." In Internet Explorer of course you get total rubbish. Anything from "page cannot be loaded" to "403 no permission." The thing is, I figured the first two at least could handle it, maybe
3
1794
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 include(). But I want to also serve them through RSS, and found that in that case the PHP source code is served -- it's not being evaluated. So it seems obvious that I need to first evaluate those PHP snippets, store the result in a variable, and use...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8872
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6674
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5307
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3964
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.