gpt4 book ai didi

php - 将 pdf 从 blob 嵌入到 html/php 页面

转载 作者:行者123 更新时间:2023-11-30 00:37:09 25 4
gpt4 key购买 nike

我将 PDF 文档作为 LONGBLOB 存储在数据库中。有没有办法将这些 PDF 嵌入到网页中?我找到了 JavaScript 的 PDFObject,但它只适用于存储在文件夹中的 PDF 文件。或者,我可以将 Blob 转换为 PDF 并读取足够长的时间吗?

目前,我使用以下脚本打开 PDF:

require_once 'init.php';

$sql = "SELECT data FROM dms_files WHERE id=42";

// the result of the query
$result = mysql_query("$sql") or die("Invalid query: " . mysql_error());

// set the header for the image
header( "Pragma: private");
header( "Cache-Control: max-age=0");
header("Content-type: application/pdf");
header('Content-Transfer-Encoding: binary');
header('Content-Description: File Transfer');
header('Content-Transfer-Encoding: binary');

echo $pdf;

它将 PDF 作为文件打开,但不会将其嵌入到页面中。

上传 PDF:

$docData = addslashes(file_get_contents($_FILES['document']['tmp_name']));
$docProperties = filesize($_FILES['document']['tmp_name']);
$sqldoc = "INSERT INTO dms_files(mime ,data) VALUES('{$docProperties}', '{$docData}')";
$current_id = mysql_query($sqldoc) or die("<b>Error:</b> Problem on Doc. Insert<br/>" . mysql_error());
$docId = mysql_insert_id();

我尝试使用这个:

<?php
require_once 'init.php';

$sql = "SELECT * FROM dms_files WHERE id = 42 ";

// the result of the query
$result = mysql_query("$sql") or die("Invalid query: " . mysql_error());
$row = mysql_fetch_row($result);

$basedir = 'LIB/';
$pdfname = strtolower(preg_replace('/([^\w\d\-_]+)/', '-', $row->nazov_rd));
$filename = $basedir . $pdfname . '_' . $row->id. '.pdf';
$file_content = base64_decode($row->data);
file_put_contents('filename.pdf', $row->data);

?>

但是,它显示以下错误:

Notice: Trying to get property of non-object in /Applications/XAMPP/xamppfiles/htdocs/D/PDFSHOW/pdfshow.php on line 11

Notice: Trying to get property of non-object in /Applications/XAMPP/xamppfiles/htdocs/D/PDFSHOW/pdfshow.php on line 12

Notice: Trying to get property of non-object in /Applications/XAMPP/xamppfiles/htdocs/D/PDFSHOW/pdfshow.php on line 13

Notice: Trying to get property of non-object in /Applications/XAMPP/xamppfiles/htdocs/D/PDFSHOW/pdfshow.php on line 14

出了什么问题?当我打开 filename.pdf 时,预览显示“该文件无法打开,因为它是空的”

<小时/>

我能够解决它;缺少这个:

while($row = mysql_fetch_object($rs)){

最佳答案

创建一个不同的页面,使用 javascript pdfobject 嵌入此元素。

关于php - 将 pdf 从 blob 嵌入到 html/php 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22075847/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com