javascript - 执行某些 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 ”。
解决方案
推荐阅读
- python - 在 Windows 上安装 simplecrypto 时出错
- javascript - 使用 .call() 的 JavaScript 继承
- c++ - 删除 Netbeans 中的标准运行参数
- jquery - 有没有办法在没有任何第三方插件的情况下让引导自动完成文本字段?
- vbscript - Visual Basic 比较文件任务
- bash - 查看多个 git 仓库的日志
- sql-server - SQL Server: Why is the backup speed so slow?
- javascript - 如何使 DIV 元素默认关闭?
- matrix - 使用 2D 矩阵和自定义 tic 绘制单元格边框
- javascript - jQuery可排序序列化无法识别动态添加的内容