使用PHP错误查看存储在MySQL数据库中的PDF文件 [英] Viewing PDF files stored in MySQL database using PHP error
问题描述
我正在创建一个按钮,单击它可以在新窗口中查看上传到 MySQL 数据库中的 PDF这是我的代码:
I am creating a button, that on click it views the PDF uploaded in the MySQL database in new window here's my code:
按钮:
<td><a href='view.php?id={$row['id']}'>View</a></td>
view.php:
<?php
header('Content-type: application/pdf');
echo $pdf_from_database;
代码似乎可以工作,并且启动了 newtab,adope 开始加载,然后出现错误:
the code seems to work and newtab is started, adope start loading, and then I get an error:
文件不以%pdf-"开头
file does not begin with "%pdf-"
有人知道如何解决这个问题吗?
Anyone knows how to solve the problem?
推荐答案
这里缺少一些链接.
- 首先应将 pdf 文件存储在服务器上的某个位置.
- 您在数据库中存储的是与 pdf 文件相关的信息,例如指向它的 url 链接.
所以假设您有一个页面 http://www.mypage.com 并且您的 pdf 文件已存储在 http://www.mypage.com/pdf/
so lets say you have a page http://www.mypage.com and your pdf files are store in http://www.mypage.com/pdf/
您在那里存储了一个名为 file_DBid_83.pdf 的 pdf 文件
you have a pdf file stored in there called file_DBid_83.pdf
当您进行 mysql 查询以打开该文件时,您的查询将返回 $row['id'] 例如 83
when you make a mysql query to open that file, your query returns $row['id'] which is 83 for example
打开你要去的文件
header('Content-type: application/pdf');
echo "/pdf/file_DBid_" . $row['id'] . ".pdf";
这篇关于使用PHP错误查看存储在MySQL数据库中的PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!