我正在尝试检索存储在 mysql 数据库中的 pdf 文件并将其显示在浏览器中。单击查看按钮时,显示错误:无法加载 pdf 文档
。
我的代码如下:
$query= mysql_query("SELECT uploaded_file FROM pdf_file where id='2'");
header('Content-Description: File Transfer');
header("Content-type: application/pdf");
header('Content-disposition:inline; filename="'.$query.'"');
@read($query);
在上面的代码中,当单击查看按钮时,会传递一个文件 ID。
最佳答案
您没有使用结果集...
$result= mysql_query("SELECT uploaded_file FROM pdf_file where id='2'");
$row=mysql_fetch_row($result);
$file = $row['uploaded_file'];
header("Content-type: application/pdf");
@read($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($file));
@read($file);
关于php - 在浏览器中从mysql数据库查看pdf文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17701502/