Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

Viewing a PDF on webpage from a MYSQL DB

Links for php scripts

Moderators: macek, egami, gesf

Viewing a PDF on webpage from a MYSQL DB

Postby lfpeck » Wed Jul 27, 2011 12:23 pm

Hello everyone, I am developing a php website for a research program at college this summer and I have ran into a slight problem.

I am trying to retrieve a PDF from a mysql database and then display it on the webpage. If I go into the MYSQL Workbench I can download the file and it displays correctly.

However, whenever I try to display it on the webpage it just gives me an empty grey screen. Here is my php file that tries to display it.

Code: Select all
<?php
   header("Content-Length: " . strlen($scanblob) );
   header("Content-Type: application/pdf");
   header("Content-Transfer-Encoding:* binary \n");
   header("Cache-Control: no-cache");
   header("Pragma: no-cache");
?>

<html>
   <title>Scan</title>
   <body>
   <?php echo ad($scanblob); ?>
   <p>Debugging Purpose</p>
   </body>
</html>




The next one is my controller that mediates the communication between my view and model.

Code: Select all
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*************************************************display_image()********************************************************/
   public function display_image($graphicid)
   {
      //Get the scanblob from the db
      $this->load->model('mucs_model');
      $image_info = $this->mucs_model->get_imageblob($graphicid);
   
      $imageblob = $image_info['imageblob'];
      $imageblob = addslashes($imageblob);
      $imagedescription = $image_info['imagedescription'];
      
      $data = array('imageblob' => $imageblob, 'imagedescription' => $imagedescription);
      
      $this->load->view('image_view', $data);
   }

/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ END display_image()@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




The final code snippet is the one that communicates with the database.


Code: Select all
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*************************************** get_scanblob($graphicid) ******************************************************/
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   public function get_scanblob($graphicid)
   {
      $scan_query = mysql_query("SELECT scanblob, scandescription FROM scan WHERE scanid = (SELECT scanid FROM graphic WHERE graphicid = '$graphicid')");
      $scan_info = mysql_fetch_array($scan_query);
      
      return $scan_info;
   }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ END get_scanblob($graphicid)@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////





The table looks like this

CREATE TABLE scan(
scanid INTEGER NOT NULL AUTO_INCREMENT,
scantype TINYTEXT,
scanblob LONGBLOB,
scandescription VARCHAR(45),
scansize VARCHAR(45),
PRIMARY KEY(scanid));


I was wondering if there is anyway that someone could help point me in the right direction. Any help would be much appreciated! Thanks, Logan
lfpeck
New php-forum User
New php-forum User
 
Posts: 1
Joined: Wed Jul 27, 2011 12:18 pm

Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron