【发布时间】:2017-10-31 11:51:20
【问题描述】:
我想从我的 MySQL 数据库中的 BLOB 中获取 PDF 文件。用于显示 PDF 的 PHP 工作正常:
<?php
$mysqli = new mysqli("192.168.1.11", "root", "password", "DB");
if ($mysqli->connect_errno) {
die("Connection refused: " . $mysqli->connect_error);
}
try{
$sql = "SELECT file FROM table WHERE id = 1";
$result = mysqli_query($mysqli, $sql);
$row = mysqli_fetch_object($result);
header('Content-type: application/pdf');
echo $row->file;
}catch(Exception $e){
echo "caught exception: ", $e->getMessage(), "\n";
}
?>
现在我想将此 PDF 文件嵌入到 HTML 中。我试过这样的事情:
<?php
$pdf = "MY_PDF_FILE.PDF"; ◄
echo <<<BLOCK
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Embeded PDF</title>
</head>
<body>
<embed src="$pdf" type="application/pdf" height="25%" width="25%">
</body> ▲
</html>
BLOCK;
?>
我尝试用$pdf = $row->file; 将$row->file; 保存在$pdf 中。总是当我尝试调用我网站的 index.php 时,它会显示 PDF 文件无法显示,我只能看到浏览器的 PDF 查看器。
有人可以帮我解决这个问题吗? :/
【问题讨论】:
-
$pdf应该是显示 PDF 文件的第一个脚本的 URL。 -
谢谢 barmar,这很有效 :) 很抱歉这个简单的问题