I'm storing pdf files as blobs in a database, but when I try to display them, I end up with the binary data being displayed rather than the actual file. I figured I should do it in pretty much the same way as with images, but it doesn't work at all. Can I use the IMG tag to display the file, or do I need to do it in a different way? I've tried using the anchor tag as well, but no luck... Has anybody got any suggestions?

/Nina

snippet from the displaying page:

<?php

dbconnection();

$query = "SELECT * FROM pdf WHERE id_no='2'";

$result=mysql_query($query);

$row=mysql_fetch_array($result);

echo $row['id_no'];

?>

<A HREF="getpdf.php?id_no=<?php echo $row['id_no']; ?>">pdf</A>

<BR>

<IMG SRC="getpdf.php?id_no=<?php echo $row['id_no']; ?>">

getpdf.php:

<?php

include "functions.php";


if($id_no) 
{


    dbconnection();

    $query = "select pdf from pdf where id_no='$id_no'";
    $result = MYSQL_QUERY($query);




$data = MYSQL_RESULT($result,0, "pdf");

    header("Content-type: application/pdf");
    header("Content-Disposition: attachment; filename=$id_no.pdf");
    echo $data;

}

?>

    Are you sure that headers haven't already been sent before you send yours? Check the top of the pdf and see if you have an error message saying headers have already been sent.

      5 days later

      For some reason, the next day when I tried it again, it worked... very strange, but there you go... 😉 It only works with the anchor tag though - I don't know why I wanted to try it with the IMG tag - must have been a bit confused... 😉

        Write a Reply...