【发布时间】:2016-05-06 07:31:58
【问题描述】:
我将 pdf 存储在文件系统和数据库表中的路径上。我现在想根据 ID 在浏览器中打开对应的 PDF 文档。如何打开和阅读 PDF? 我目前拥有的是这个
require_once("database.php");
if(isset($_GET['upload_id']) && is_numeric($_GET['upload_id']))
{
$fileFolder='uploads/';
$sql = "SELECT file FROM documents WHERE upload_id = :id";
$result = $pdo->prepare($sql);
$result->bindParam(":id", $_GET['upload_id']);
$result->execute();
$resArray = $result->fetchAll();
$file = $resArray['file'];
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Type: application/pdf');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($fileFolder.$file));
@read($fileFolder.$file);
}
当我单击按钮并尝试打开 pdf 时,我在 Chrome 中收到了这条消息
无法加载 PDF 文档 重新加载
【问题讨论】:
-
$file在您的代码中未定义!! -
这是我复制/粘贴源代码时的错误。我已经编辑了我的问题。
-
确保 $file 上存储的路径正确,并尝试 $fileFolder 的绝对路径
-
echo
$fileFolder.$file并检查您的路径 -
我没有得到文件名.. 当我
echo $fileFolder.$file我只有文件夹:uploads/