0

How to view .pdf file in a webpage using PHP? The pdf file is in a mysql database. Thanks.

1
  • Is the file itself in the database, or is the filename in the database? And how is it stored? Just as binary data or in any other way? Commented Apr 12, 2011 at 8:49

2 Answers 2

2

If you echo the contents from the database to the browser and provide the appropriate content type through HTTP headers you're done!

<?php

header('Content-type: application/pdf');
echo $pdf_from_database;
Sign up to request clarification or add additional context in comments.

Comments

1

The pdf file is in a mysql database

Shocking! They are rarely good results in saving files in a database. Directories are better storing places for files.

header('Content-type: application/pdf');
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("Content-Disposition: inline;filename='document.pdf'");
header("Content-length: ".strlen($binary_contents_from_database));

echo $binary_contents_from_database;

If a PDF plug-in is available for the browser, then the document will be displayed inline, otherwise it will be given as a download.

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.