php - 无法使用 php 和 Jquery 打开 PDF 文件
问题描述
在我的情况下,无法显示所有 pdf 文件,有些 pdf 可以在浏览器上查看,有些无法查看,试图回显 pdf 文件但不能一直工作,顺便说一下,我所有上传的文件都上传到了MySql 数据库.. 我不使用文件夹来移动上传的文件.. 请参阅我的 jquery 代码和 php 代码
$.ajax({
url:'fetchAllAttachenemts.php',
method:'POST',
data:{DispID:DispID},
success:function(data)
{
if ( data == '')
{
$('#AttachementTable tbody' ).html( ' <tr> <td></td><td>No Files Were Uploaded</td><td></td></tr>');
}
else
{
$('#AttachementTable tbody' ).html(data);
}
},
error:function(data)
{
alert(data);
}
});
include 'connect.php';
global $con;
if (isset($_GET['id']))
{
$ID = $_GET['id'];
$stat = $con->prepare("SELECT * FROM dispatchattachmnt WHERE ID = ? ");
$stat->bindParam(1,$ID);
$stat->execute();
$row = $stat->fetch();
$file = $row['fileName'];
$filename = $row['fileName'];
header('Content-type: '.$row['fileMimi']); // = header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="'.$filename.'"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
//echo (@readfile($file));
echo $row['data'] ; // from blob in mysql
}
else
{
echo "NOT SET";
}
她是我获取附件的代码
session_start();
include 'connect.php';
global $con;
$outpout='';
$ID= "";
if (isset($_POST['DispID']))
{
if($_POST['DispID'] !="")
{
$id = $_POST['DispID'];
$query= "SELECT * FROM dispatchattachmnt WHERE dispID = ?";
$stmt = $con->prepare($query);
$stmt->execute(array($id));
$result = $stmt->fetchAll();
$count = $stmt->rowCount();
if ($count >0)
{
foreach ($result as $row)
{
$outpout .= '<tr>';
$outpout .= '<td id = "'.$row['ID'].'" style="cursor:pointer"> <span class="modifyAttacheDesc"> '.$row['disc'].' </span></td> ';
$ID = trim($row['ID']);
$outpout .= '<td id = "'.$row['ID'].'" class="openAtt"> <a target="_blank" href="viewAttachement.php?id='.$row['ID'].'">'.$row['fileName'].'</a></td>';
$outpout .= '<td id = "'.$row['ID'].'" ><i id ="'.$row['ID'].'" class="fas fa-trash-alt task-icon2" </i></td>';
$outpout .='</tr>';
}
echo $outpout;
}
}
}```
解决方案
推荐阅读
- go - 为什么当 annoymouse 函数返回时 defer 语句的工作方式不同
- python - Python - 为绘图构建数据框
- google-cloud-platform - 双引号字符串数据在谷歌存储上以三引号显示
- java - 如何在 5 小时后强制会话退出 TOMCAT 服务器(不是非活动会话退出)
- python - 无法注册碰撞
- firebase - 如何在 Firebase 上创建 Busuu 每日提醒通知
- aws-lambda - 功能即服务 (FaaS) 托管如何在后台工作?
- go - 为什么 go-jaeger-client 需要度量和日志的包装器?
- reactjs - 为什么 Scrollspy 未在反应应用程序中加载?
- java - 异步回调和监听器