473,396 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

problem displaying pdfs from mysql

Hi I have uploaded a pdf file into my db and am trying to display it
again here is the code i have used (at the moment it is just displaying
the binary file's code as text in a html page:

<?php session_start();
include("connection.php");

$query = "SELECT resource, resource_name FROM tblresources WHERE id =
'3' ";

$result = mysql_query($query) or die(mysql_error() );

$row = mysql_fetch_array($result);
$content = $row['resource'];

header("Content-type: application/pdf");

echo $content;

?>

//am i missing something else to go with header to make it be read as a
pdf file?

Please help!

May 7 '06 #1
5 1564
Rik
monomaniac21 wrote:
header("Content-type: application/pdf");


add:
header('Content-Disposition: attachment; filename="somename.pdf"');

should work, BTW directy from
http://nl3.php.net/manual/en/function.header.php

Grtz,
--
Rik Wasmus
May 7 '06 #2
Cheers Rik is that also required for displaying jpgs and stuff? i dont
remember using it.

May 7 '06 #3
Rik
monomaniac21 wrote:
Cheers Rik is that also required for displaying jpgs and stuff? i dont
remember using it.


Not for images, no. Allthough some browsers (I know IE does) display pdf's,
it's not HTML, it's officially not for a browser to handle. Browsers can
display HTML and other "simple" files (for instance XML, TXT, all files
easily made in notepad and the like), and (most) images.

Other files have to be first downloaded and then displayed with other
programs. IE uses an external pdf-reader (normally acrobat), but pretends it
is capable of displaying pdf's by running the program "inline" (for lack of
a better word, my english is limited). Hence the confusion.

That's putting it simple. I'm sure there are people on this ng that DO know
what they are talking about who can correct me, but this explanation has
sufficed for me so far :-)

Grtz,
--
Rik Wasmus
May 7 '06 #4
Rik wrote:
monomaniac21 wrote:

header("Content-type: application/pdf");


add:
header('Content-Disposition: attachment; filename="somename.pdf"');

should work, BTW directy from
http://nl3.php.net/manual/en/function.header.php

Grtz,

And I've found that you need to use:
header('Content-Disposition: inline; filename="somename.pdf"');
.... to display it in the browser

To create a download, save as dialog use:
header('Content-Disposition: attachment; filename="somename.pdf"');

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
The world is my country,
Science, my religion
*****************************
May 7 '06 #5
Rik
Chuck Anderson wrote:
And I've found that you need to use:
header('Content-Disposition: inline; filename="somename.pdf"');
... to display it in the browser

To create a download, save as dialog use:
header('Content-Disposition: attachment; filename="somename.pdf"');


As I said, some people do know what they're talking about :-)

Grtz,
--
Rik Wasmus
May 7 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mark | last post by:
Hello, I am new to PERL and I want to do a simple function (in LINUX): find all files that have the extension pseudo.pdf and put the file names in a file; parse the file and change all file...
0
by: billby | last post by:
Hi all, I am trying to solve a problem on a production server, that unfortunately is not repeatable on our development server. It is for a bank, and the site is being hosted by a different...
0
by: Shawn Hogan | last post by:
I'm wondering what my options are for displaying PDFs in my winform. I'd rather not have adobe acrobat reader installed to do this. So far i've looked at adding the pdf.ocx COM component to my...
14
by: BlueDolphin | last post by:
Hello all. I'm looking for some opinions on using snapshot files or ..pdf for some reports. We are in the initial stages of creating some reports in access that will be pulled online through Cold...
0
by: Scott McFadden | last post by:
My aspx page code reads some custom values from the HTTP headers and then writes a given pdf to the output stream based upon the header values. Unforunately, my code causes IE to pop up an Open /...
3
by: Mike Kingscott | last post by:
Hi there, I'm writing an app in which a punter buys some PDFs online. After purchasing said PDFs, they will be given a token (bless them Guids) to go to a download .ASPX page from which they can...
2
by: donpro | last post by:
Hi, I have a varchar field in a MySQL database that contains a line of text like so: "This is a line if text" The double quotes are included in the database field. I cannot seem to...
0
by: John Kirkpatrick | last post by:
Hi all, I am having difficulty displaying records on a frontend MS Access 2000 form using a MySQL backend. The following code works well with the Jet database engine but doesn't work properly...
0
by: praveenkhade | last post by:
I am working on asp.net ,C#. The pdf files in the grid are displaying properly. The main prob is that in these pdfs one pdf is the main like an index ,if i open this pdf i can link to rest of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
0
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...

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.