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?

1
  • 3
    Whatever you have in $pdf_from_database is not a valid PDF file. Post the code that creates that. Commented Mar 13, 2012 at 21:46

1 Answer 1

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";
Sign up to request clarification or add additional context in comments.

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.