开发者

PHP code in viewing a pdf file from a mysql database

开发者 https://www.devze.com 2023-02-24 04:52 出处:网络
开发者_开发问答How to view .pdf file in a webpage using PHP? The pdf file is in a mysql database. Thanks.If you echo the contents from the database to the browser and provide the appropriate content t
开发者_开发问答

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


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;


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消