首页 > 解决方案 > 执行某些 PHP 代码后如何使用 Pdf.js 查看器打开 PDF 文件?(没有 ?file=URL_PDF)

问题描述

我不知道我的问题标题是否足够好。

我尝试使用 PDf.js 在我的网站中构建 pdf 查看器。我知道,通常它很简单: http ://example.com/pdfjs/web/viewer.html?file=PDF_URL

但我的主张是 - Pdf url 不显示在地址栏中。我是从 viewer.html 代码创建 view.php 的。我想要这样: http ://example.com/pdfjs/web/view.php?file=1

所以在我的 php 页面中,我检查数据库并从 ID=1 获取 fileurl。

最后我想设置 Pdf.js 查看器以从 Fileurl 打开我的 pdf。但我不能。我为此浪费了很多时间,谷歌搜索了几个小时,但不幸的是我不能。

我能做些什么?或者我该怎么做才能得到这样的结果?或者使用 .htaccess 是否有可能?(对不起我的英语质量差)

<?php
// my view.php

if(isset($_GET['file'])){
  $file = mysqli_real_escape_string($db, @$_GET['file']);
}else{
  $file="";
}

if(is_numeric($file) AND $file!=""){
  $query = mysqli_query($db, "select * FROM pdf_files WHERE id='$file' ");
     if(mysqli_num_rows($query) == 1){
        $result = mysqli_fetch_assoc($sorgu);
        $filepath = $result['filepath'];
}

?>

<!DOCTYPE html>
<head>
  <link rel="resource" type="application/l10n" href="locale/locale.properties">
  <script src="../build/pdf.js"></script>
  <script src="viewer.js"></script>
  <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
</head>
<body>
  <!--Other Pdf.js viewer.html codes-->
</body>
</html>

现在当我要去http://example.com/pdfjs/web/view.php?file=1时,

PdfJS 给出这样的错误:消息:缺少 PDF“ http://example.com/pdfjs/web/1 ”。

标签: javascriptphp.htaccesspdfpdf.js

解决方案


推荐阅读