0

There is a pdf file stored in my database as a [BLOB - 143.3 KiB]. It's got a userid of 12. I am trying to call it to the page so that when I click on a button, the pdf populates the webpage.

if (isset($_POST["work"]) && !empty($_POST["work"])) 
 {
   $result = mysql_query("SELECT file FROM ce WHERE userid=12", $c) or die("six");
   $document1=mysql_result($result, 0, 'file'); 
   echo $document1;
 }

 echo '
       <form action="yourcase.php" method="post">
          <input type="hidden" name="work" value="1">
          <input type="image" id="work" src="images/papers.png">
       </form>'; 

Currently, it echos out a page of this: ‰ŒA Â@E÷9Å_ê&&Ói[Ž€°£ ZqŠôúÆŽ@ïåÿ&ŠÆÑ,¢Y[«*ÆX%Ó@/RˆOÝçÇ¡.

Using another post, I was able to call a pdf file from my desktop, but I can't figure out how to do it from the database.

$file = 'sample.pdf';
$filename = 'sample.pdf'; 
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');
@readfile($file); 

Thanks to @Fred, I was able to piece together a working solution. This does what I've been trying to do:

if (isset($_POST["work"]) && !empty($_POST["work"])) 
 { 
   $result = mysql_query("SELECT file FROM ce WHERE userid=12", $c) or die("six");
   $document1=mysql_result($result, 0, 'file'); 
   header('Content-type: application/pdf');
   echo $document1;
 }

 echo '
        <form action="fetchdoc.php" method="post">
           <input type="hidden" name="work" value="1">    
           <input type="image" id="work" src="images/papers.png">
        </form>'; 
13
  • Why 2 different file names? $filename - $file Commented Aug 10, 2013 at 2:29
  • I got it from here stackoverflow.com/questions/4679756/… Commented Aug 10, 2013 at 2:31
  • That's in case you wish to call it "another" name, hence $filename = 'Custom file name for the.pdf'; which I doubt you want to do, unless you want to email it as an attachment or for downloading under another name. Commented Aug 10, 2013 at 2:32
  • Have a look at this question on SO, including my answer on the same page. It may be of help stackoverflow.com/questions/17872470/… Commented Aug 10, 2013 at 2:37
  • thanks Fred, but that didn't work for me. Commented Aug 10, 2013 at 2:42

3 Answers 3

1

Look through these links which may be of help.

Sign up to request clarification or add additional context in comments.

Comments

0

Your going to have to create the pdf file and then use header to read that file. If you don't plan on keep the files, you can load them to a temp directory and then delete them when your done. If you echo the blob data from your database, its like opening a .pdf file with notepad.

1 Comment

Great. Could you show how to do that. I'm very new and all I can think of is this
0

Thanks to @Fred, I was able to piece together a working solution. This does what I've been trying to do:

if (isset($_POST["work"]) && !empty($_POST["work"])) { 
$result = mysql_query("SELECT file FROM ce WHERE userid=12", $c) or die("six");
$document1=mysql_result($result, 0, 'file'); 
header('Content-type: application/pdf');
echo $document1;}
echo '<form action="fetchdoc.php" method="post"><input type="hidden" name="work" value="1">    
<input type="image" id="work" src="images/papers.png"></form>'; 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.