Viewing PDF Image Blob

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wolfnipplechips
Forum Commoner
Posts: 32
Joined: Tue Aug 18, 2009 6:46 am
Location: Berkshire, UK

Viewing PDF Image Blob

Post 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.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: Viewing PDF Image Blob

Post 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.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Viewing PDF Image Blob

Post 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
wolfnipplechips
Forum Commoner
Posts: 32
Joined: Tue Aug 18, 2009 6:46 am
Location: Berkshire, UK

Re: Viewing PDF Image Blob

Post 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;
} 
?>
Post Reply