Page 1 of 1

Viewing PDF Image Blob

Posted: Wed Aug 19, 2009 6:38 am
by wolfnipplechips
Hi there.

I've got a pdf stored in the database (name, type, content, size)

I've made a 'view pdf' link which needs to show the blob pdf in the browser...

Code: Select all

<a href='showpdf.php?name=".$r['name']."' class='links'>Download Course PDF</a>
This passes the pdf name to the following script...

Code: Select all

<?php
 
 include("connect_course.php"); 
$name=$_GET['name'];
 
 
 header("Content-Type: application/pdf");
 echo $name;
exit();
 
?>

And I get the following error...

Warning: Cannot modify header information - headers already sent

Is $name the right one to use?

Any help will be much apreciated. Other tutorials on line seem to reall over complicate things.

Re: Viewing PDF Image Blob

Posted: Wed Aug 19, 2009 7:58 am
by yacahuma
This message only occurs if for any reason any characters are output before the header. Do a VIew Source on youyr browser and see if you see anything strange(like an error message). Also make sure that if you have any includes, they do not produce any characters. A common problem is when you have a file and close it with ?> but then enter a couple of empty lines.

You also going to need something more substantial to work properly. Take a lookg at php.net , the header function. check out the comments on that page.

Re: Viewing PDF Image Blob

Posted: Wed Aug 19, 2009 8:05 am
by Mark Baker
wolfnipplechips wrote:Warning: Cannot modify header information - headers already sent
The message should actually tell you exactly where (script file and line number) the output was sent before the headers

Re: Viewing PDF Image Blob

Posted: Wed Aug 19, 2009 9:33 am
by wolfnipplechips
Thanks guys.

I've got it working now...

Code: Select all

<?php
if(isset($_GET['name'])) 
{
include("connect_course.php"); 
 
$filename = $_GET['name'];
$query = "SELECT content FROM course WHERE name = '$filename'";
 
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
$content = $row['content'];
 
header("Content-Type: application/pdf");
echo $content;
} 
?>