如何使用javascript实时预览在MySQL服务器中保存为Longblob数据的PDF文件?

时间:2014-03-21 08:19:07

标签: javascript php mysql html5 pdf-viewer

如何在我的本地网站(没有互联网)中实时预览PDF文件,这是在Longblob中保存的PDF?我使用这个脚本下载PDF:

<?php
if(isset($_GET['id']))
{
include "../conn.php";
$query = "select * from file where id = '".$_GET['id']."'";
$result = mysql_query($query) or die (mysql_error);
$download = mysql_fetch_array($result);

$name = str_replace('%20', ' ',$download['file_name']);
$type = $download['file_type'];
$size = $download['file_size'];
$content = $download['file'];

header("Content-disposition: attachment; filename=\"".$name."\"");
header("Content-length: ".$size."");
header("Content-type: $type");
echo $content;
exit;
}
?>

我几乎使用了来自http://viewerjs.org的所有开源PDF Viewer插件,但未能显示所需的PDF文件。需要你的帮助..

1 个答案:

答案 0 :(得分:0)

你应该有一个pdf插件,你应该使用代码:

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));