显示来自数据库的 pdf blob 文件

新手上路,请多包涵

我已将 pdf 文件存储到数据库中,即 blob 类型。现在我想显示 pdf 之类的

$sqll="select * from pdff";
$query=mysql_query($sqll) or die(mysql_error());
$result=mysql_fetch_array($query);
$content=$result['pdf'];
<object data="<?php echo $content;?>" type="application/pdf" style="height:200px;width:60%"></object>

但在浏览器中它显示..

 > endobj 6 0 obj << /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] /ColorSpace << /Cs1 7 0 R /Cs2 10 0 R >> /ExtGState << /Gs2 34 0 R /Gs1 35 0 R >> /Font << /F1.0 31 0 R >> /XObject << /Im4 21 0 R /Im1 8 0 R /Im3 16 0 R /Im2 11 0 R /Im5 26 0 R /Im6 32 0 R /Fm3 23 0 R /Fm1 13 0 R /Fm2 18 0 R /Fm4 28 0 R >> /Properties << /Pl2 36 0 R /Pl1 37 0 R >> >> endobj 23 0 obj << /Length 24 0 R /Filter /FlateDecode /Type /XObject /Subtype /Form /FormType 1 /BBox [649 536 669 556] /Resources 25 0 R /Group << /S /Transparency /CS 10 0 R /I true /K false >> >> stream xMŽAƒ0ï}žÀĉmȹ/àÄU+Íÿ¥:(\|˜]ïî etc

我试过了

 <object data="<?php echo base64_decode($content);?>" type="application/pdf" style="height:200px;width:60%"></object>

但没有用……请帮助我

原文由 rch 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 337
2 个回答

如果您的数据仍在 Blob 中,则需要使用 base64_encode() 对数据进行编码。请试一试

<object data="data:application/pdf;base64,<?php echo base64_encode(content) ?>" type="application/pdf" style="height:200px;width:60%"></object>

原文由 Dolly Aswin 发布,翻译遵循 CC BY-SA 3.0 许可协议

我希望以下内容将完全符合您的要求:

 header('Content-type: application/pdf');
header('Content-Disposition: inline; filename=name.pdf');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
@readfile("data:application/pdf;base64,$content");

原文由 Jay Soni 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题