Skip to content

Commit

Permalink
merge document uploader
Browse files Browse the repository at this point in the history
  • Loading branch information
bikash committed Mar 17, 2016
1 parent bbc4879 commit 75b02fd
Show file tree
Hide file tree
Showing 9 changed files with 2,502 additions and 2 deletions.
File renamed without changes.
42 changes: 42 additions & 0 deletions demoDoctracker/web/db/dbtuts.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Dec 17, 2014 at 04:27 AM
-- Server version: 5.1.36
-- PHP Version: 5.3.0

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `dbtuts`
--

-- --------------------------------------------------------

--
-- Table structure for table `tbl_uploads`
--

CREATE TABLE IF NOT EXISTS `tbl_uploads` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`file` varchar(100) NOT NULL,
`type` varchar(30) NOT NULL,
`size` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `tbl_uploads`
--

INSERT INTO `tbl_uploads` (`id`, `file`, `type`, `size`) VALUES
(1, '70455-(r)11d.jpg', 'image/jpeg', 19),
(2, '77190-3d-glass-green-effect.jpg', 'image/jpeg', 249);
45 changes: 45 additions & 0 deletions demoDoctracker/web/file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
include_once 'dbconnect.php';
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>File Uploading With PHP and MySql</title>
<link rel="stylesheet" href="upload.css" type="text/css" />
</head>
<body>
<div id="header">
<label>File Uploading</label>
</div>
<div id="body">
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<button type="submit" name="btn-upload">upload</button>
</form>
<br /><br />
<?php
if(isset($_GET['success']))
{
?>
<label>File Uploaded Successfully... <a href="view.php">click here to view file.</a></label>
<?php
}
else if(isset($_GET['fail']))
{
?>
<label>Problem While File Uploading !</label>
<?php
}
else
{
?>
<label>Try to upload any files(PDF, DOC, EXE, VIDEO, MP3, ZIP,etc...)</label>
<?php
}
?>
</div>
<div id="footer">

</div>
</body>
</html>
3 changes: 1 addition & 2 deletions demoDoctracker/web/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
</div>

<div id="body">
This is a test

Upload the file &nbsp;<a href="file.php">Upload</a>
</div>

</body>
Expand Down
48 changes: 48 additions & 0 deletions demoDoctracker/web/upload.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@charset "utf-8";
/* CSS Document */

*
{
padding:0;
margin:0;
}
body
{
background:#fff;
font-family:Georgia, "Times New Roman", Times, serif;
text-align:center;
}
#header
{
background:#00a2d1;
width:100%;
height:50px;
color:#fff;
font-size:36px;
font-family:Verdana, Geneva, sans-serif;
}
#body
{
margin-top:100px;
}
#body table
{
margin:0 auto;
position:relative;
bottom:50px;
}
table td,th
{
padding:20px;
border: solid #9fa8b0 1px;
border-collapse:collapse;
}
#footer
{
text-align:center;
position:absolute;
left:0;
right:0;
margin:0 auto;
bottom:50px;
}
43 changes: 43 additions & 0 deletions demoDoctracker/web/upload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
include_once 'dbconnect.php';
if(isset($_POST['btn-upload']))
{

$file = rand(1000,100000)."-".$_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$folder="uploads/";

// new file size in KB
$new_size = $file_size/1024;
// new file size in KB

// make file name in lower case
$new_file_name = strtolower($file);
// make file name in lower case

$final_file=str_replace(' ','-',$new_file_name);

if(move_uploaded_file($file_loc,$folder.$final_file))
{
$sql="INSERT INTO tbl_uploads(file,type,size) VALUES('$final_file','$file_type','$new_size')";
mysql_query($sql);
?>
<script>
alert('successfully uploaded');
window.location.href='file.php?success';
</script>
<?php
}
else
{
?>
<script>
alert('error while uploading file');
window.location.href='file.php?fail';
</script>
<?php
}
}
?>
Loading

0 comments on commit 75b02fd

Please sign in to comment.