2015-11-16 76 views
0

我正在研究一个小型文档管理系统。我创建了允许我将文档上传到数据库的功能。但现在我想给用户两个选项,在线查看文档或直接下载到他们的PC。我目前正在研究'在线观看'功能,我正在努力。我发现一个名为'ViewerJS'的文档查看器,但我不知道如何整合它,我甚至按照说明操作。请参阅下面的信息:在网页上的数据库中显示保存的文档

网站文件目录:

This is my directory where I've saved all my website files

ViewerJS目录:

This is the viewerJS directory

数据库 “上传” 表:

My table where I have stored my uploaded files

第一张图片显示了我的网站文件目录,它也恰好与我上传到数据库以进行测试的文件相同。第二张图片显示了我从互联网上下载的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 --> 
+0

我们将通过查看** uploadconfig.php **文件来做什么?您的问题不在此文件中,因为它正确上传。你的问题是在线查看文件。所以,你需要给这个文件。 –

+0

我没有一个文件在线查看,这就是为什么我下载了viewerJS ..使我能够做到这一点。 –

回答

0

尝试应用如下例子

传递图片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']; 
?> 
相关问题