How do I store pdf files in mysql? 
Author Message
 How do I store pdf files in mysql?

Hi,
     I'm having problems with document storage in mysql.

I can serve Acrobat (pdf) files dynamically from a php script with:

   <?php
     # security checks etc

     header('Content-Type: application/pdf');
     header("Content-Disposition = attachment; filename=$filename");

     $file = fopen($filename,'r');
     fpassthru($file);
     fclose($file);
   ?>

What I really want to do though is to store those files in mysql. I
wrote the pdf file into a blob field using:

   mysql_query("update reports ".
               "set content=\"".mysql_escape_string($pdfobject)."\" ".
               "where key=$key ");

and replaced the server with:

   <?php
     # security checks etc

     header('Content-Type: application/pdf');
     header("Content-Disposition = attachment; filename=$filename");

     $result = mysql_query("select * from reports where key=$key);
     $r = mysql_fetch_assoc($result);
     echo $r['content'];
   ?>

This doesn't work though. IE simply brings up a blank page without being
able to view the source. Removing the header statements ands bracketing
the echo with <html> </html> displays the pdf source fine.

Can anyone tell me what I'm doing wrong?

TIA



Sun, 26 Jun 2005 00:40:08 GMT  
 How do I store pdf files in mysql?

Quote:

>    mysql_query("update reports ".
>                "set content=\"".mysql_escape_string($pdfobject)."\" ".
>                "where key=$key ");

i would be Really Surprised if this works. i would expect the
mysql_escape_string() call to hose by BLOB data.

google:saving images to a mysql database with php

http://php.resourceindex.com/detail/00766.html
http://www.oreillynet.com/pub/a/php/2000/09/15/php_mysql.html

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.



Sun, 26 Jun 2005 00:35:10 GMT  
 How do I store pdf files in mysql?

Quote:
> i would be Really Surprised if this works. i would expect the
> mysql_escape_string() call to hose by BLOB data.

> google:saving images to a mysql database with php

> http://php.resourceindex.com/detail/00766.html
> http://www.oreillynet.com/pub/a/php/2000/09/15/php_mysql.html

been there, done that...... he uses addslashes. I get exactly the same
mileage.


Sun, 26 Jun 2005 01:14:59 GMT  
 How do I store pdf files in mysql?


Quote:
> Hi,
>      I'm having problems with document storage in mysql.

> I can serve Acrobat (pdf) files dynamically from a php script with:

>    <?php
>      # security checks etc

>      header('Content-Type: application/pdf');
>      header("Content-Disposition = attachment; filename=$filename");

>      $file = fopen($filename,'r');
>      fpassthru($file);
>      fclose($file);
>    ?>

> What I really want to do though is to store those files in mysql. I
> wrote the pdf file into a blob field using:

>    mysql_query("update reports ".
>                "set content=\"".mysql_escape_string($pdfobject)."\" ".
>                "where key=$key ");

> and replaced the server with:

>    <?php
>      # security checks etc

>      header('Content-Type: application/pdf');
>      header("Content-Disposition = attachment; filename=$filename");

>      $result = mysql_query("select * from reports where key=$key);
>      $r = mysql_fetch_assoc($result);
>      echo $r['content'];
>    ?>

> This doesn't work though. IE simply brings up a blank page without being
> able to view the source. Removing the header statements ands bracketing
> the echo with <html> </html> displays the pdf source fine.

> Can anyone tell me what I'm doing wrong?

> TIA

------------------------
Kevin,
Try this - it works for me for images and word documents so i don't see wht
it shouldn't work on PDF's

the db_query and db_fetchall_array are wrappers for mysql functions.
Note that when i store the image in a blob i also store the type ( and size
though i don't use it)

  $result=db_query(array($Qc)) or die("Query Failed : ".db_error());
  $Rows = db_fetchall_assoc(array($result));
  foreach($Rows as $Row) {
     $HType = $Row["fType"];
     $Data  = $Row["Image"];
  }
  Header("Content-type: $HType");
  echo $Data;
db_close();

Regards

Ron



Sun, 26 Jun 2005 09:38:11 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Receiving files stored as MySQL blobs

2. storing binary files to mySQL ???

3. More problems with pdf / mysql

4. Store for mySQL?

5. Store + mysql?

6. MySQL now has stored procedures

7. Store Array in MySQL Database

8. Changing date format when doing MySQL query?

9. Store python list in MySQL

10. Storing a Python Dictionary in MySQL

11. Storing a JPEG in MySQL-Database

12. Converting PDF files to WMF files

 

 
Powered by phpBB® Forum Software