【问题标题】:Displaying saved documents in a database on a webpage在网页上显示保存在数据库中的文档
【发布时间】:2016-02-17 15:55:15
【问题描述】:

我正在开发一个小型文档管理系统。我创建了允许我将文档上传到数据库的功能。但现在我想给用户两个选项,在线查看文档或直接下载到他们的 PC。我目前正在开发“在线查看”功能,但我正在苦苦挣扎。我找到了一个名为“ViewerJS”的文档查看器,但我不知道如何集成它,我什至按照说明进行操作。更多信息见下文:

网站文件目录:

ViewerJS 目录:

数据库“上传”表:

第一张图片显示了我的网站文件目录,这也恰好是我上传到数据库中用于测试目的的相同文件。第二张图片显示了我从 Internet 下载的 viewerJS 目录。第三张图片显示了我在存储我上传文件的数据库中的表。我真的很难在viewerJS文档查看器中显示数据库中的内容..有人可以帮忙吗?另请参阅下面的 uploadconfig.php 文件:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

include("dbconfig.php");
if(isset($_POST['btn-upload'])){

if (empty($_FILES['file']['name'])){
    header("location:upload.php?msg0= Please select a file to upload.");

} else {

$loggedinuser = $_GET['bid'];

$file = $_FILES['file']['name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$sql = mysqli_query($conn, "INSERT INTO upload (personalid, file, type, size) values ((select personalid from person where username='$loggedinuser'), '$file', '$file_type', '$file_size')") or die (mysqli_error($conn));

if($sql){
    header("location:upload.php?msg1= Document Uploaded.");     
}
else {
    header("location:upload.php?msg2=Document Not Uploaded.");
}
}
}


?>
<!-- need to commentt -->

【问题讨论】:

  • 通过查看 uploadconfig.php 文件我们会做什么??您的问题不在于此文件,因为它正在正确上传。您的问题是在线查看文件。所以,你需要提供那个文件。
  • 我没有文件可以在线查看,所以我下载了 viewerJS.. 来让我这样做。

标签: javascript php file-upload mysqli viewer


【解决方案1】:

尝试按照以下示例申请

传递图像 ID(例如 id=1)

<a class="view" href="/ViewerJS/#../path/to/image.php?id=1">…</a>

检查这个网址 - http://finegoodsmarket.com/view

image.php文件代码如下

<?php

  $id = $_GET['id'];

  $link = mysql_connect("localhost", "root", "");
  mysql_select_db("testdb");
  $sql = "SELECT image FROM table WHERE id=$id";
  $result = mysql_query("$sql");
  $row = mysql_fetch_assoc($result);
  mysql_close($link);

  header("Content-type: image/jpeg");
  echo $row['image'];
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 2018-03-08
    • 2014-02-17
    相关资源
    最近更新 更多