1

I am creating a button, that on click it views the PDF uploaded in the MySQL database in new window here's my code:

Button:

<td><a href='view.php?id={$row['id']}'>View</a></td>

view.php:

<?php

header('Content-type: application/pdf');
echo $pdf_from_database;  

the code seems to work and newtab is started, adope start loading, and then I get an error:

file does not begin with "%pdf-"

Anyone knows how to solve the problem?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Mo T
  • 440
  • 2
  • 9
  • 30
  • 3
    Whatever you have in $pdf_from_database is not a valid PDF file. Post the code that creates that. – Cfreak Mar 13 '12 at 21:46

1 Answers1

1

you are missing some links here.

  1. first the pdf files should be stored somewhere on a server.
  2. what you store in the database is information relative to the pdf file such as a url link to it.

so lets say you have a page http://www.mypage.com and your pdf files are store in http://www.mypage.com/pdf/

you have a pdf file stored in there called file_DBid_83.pdf

when you make a mysql query to open that file, your query returns $row['id'] which is 83 for example

so to open the file you go

header('Content-type: application/pdf');
echo "/pdf/file_DBid_" . $row['id'] . ".pdf";
Khalid
  • 194
  • 1
  • 1
  • 7