0

I am working on a small document management system. I have created the function that allows me to upload a document to the database. But now I want to give a user two options, view the document online or download it straight to their PC. I'm currently working on the 'view online' function and I'm struggling. I found a document viewer called 'ViewerJS' but I do not know how to integrate it, I've even followed the instructions. See below for more information:

Website File Directory:

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

ViewerJS Directory:

This is the viewerJS directory

Database "Upload" Table:

My table where I have stored my uploaded files

The first image shows my website file directory, which also happen to be the same files that I uploaded to the database for testing purposes. The second image shows the viewerJS directory, that I downloaded from the internet. And the third image shows my table in the database where my uploaded files are stored. I really am struggling to display what's in the database, in the viewerJS document viewer.. can anyone help? Also see my uploadconfig.php file below:

<?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 -->
mugzi
  • 809
  • 4
  • 16
  • 33
  • What we will do by seeing **uploadconfig.php** file ?? Your problem is not with this file since it is uploading correctly. Your problem is to view file online. So, you need to give that file. – Nana Partykar Nov 16 '15 at 14:10
  • I don't have a file to view it online, that is why I downloaded viewerJS.. to enable me to do that. – Muhammad Sohail Arif Nov 16 '15 at 14:10

1 Answers1

0

Try to apply as follow example

Pass the Image Id (example id=1)

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

Check this url - http://finegoodsmarket.com/view

In image.php file code as below

<?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'];
?>
mugzi
  • 809
  • 4
  • 16
  • 33