dongpangfu6322 2017-10-10 12:44
浏览 64
已采纳

用php显示数据库中的pdf文件

I've been using this code to show my images

        <dd><?php echo '<img src="data:image/jpeg;base64,'.base64_encode( $result['image'] ).'"/>';

But when I want to show an pdf file I get nothing on my page, i only get my the frame from the iframe tag.

I've using this code to show my pdf file (also stored as a blob):

        <dt> <?php echo '<iframe src="data:application/pdf;base64,'.base64_encode( $result['image'] ).'"</iframe>'; ?></dt>
  • 写回答

1条回答 默认 最新

  • douan3414 2017-10-10 13:01
    关注

    There are different possible reasons why you have the problem:

    1. The data in the database is corrupt
    2. The retrieval of the data from the database leads to corrupted data
    3. The HTML you created simply doesn't work in your browser.

    To find out the culprit, you can do the following steps:

    • Retrieve the PDF-data from the database manually and try to open it in a PDF-reader. If that doesn't work, your PDF-data in the table is most likely corrupt. Check the process saving the data to the database.
    • Encode the retrieved data to base64 (check if that was done correctly by decoding it again and open the decoded data in the reader).
    • Output the base64 encoded text from you PHP-script and compare the two base64-blocks for equality. If they differ, your script seems to corrupt the data when retrieving the data from the DB.
    • Create a static HTML-page, using the base64-data you generated before and open it in a browser. If that doesn't work, your HTML is not correct for embedding PDF into it or the browser simply doesn't support showing PDF embedded.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?