· 8 years ago · Mar 29, 2018, 07:12 PM
1/* All Resources for Apache Web Server On Windows:
2
3Setup Tutorial: https://miloserdov.org/?p=55
4
5* Download Apache for Windows: https://www.apachelounge.com/download/
6* Download PHP 7 for Windows (select ‘Thread Safe’): http://windows.php.net/qa/
7* Download MySQL for Windows (select ZIP Archive): http://dev.mysql.com/downloads/mysql/
8* Download phpMyAdmin: https://www.phpmyadmin.net/
9* Download the latest C++ Redistributable Visual Studio 2017: (direct link to download the 64-bit version, a direct link to the download of the 32-bit version).
10* Download Visual C++ Redistributable Packages for Visual Studio 2013: https://www.microsoft.com/en-US/download/details.aspx?id=40784
11*/
12
13// Database Creation Code //
14/*===============================================================================*/
15
16CREATE DATABASE `demo` ;
17Use `demo`;
18CREATE TABLE IF NOT EXISTS `tbl_files` (
19 `id` int(9) NOT NULL AUTO_INCREMENT,
20 `filename` varchar(255) NOT NULL,
21 `created` datetime NOT NULL,
22 PRIMARY KEY (`id`)
23) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
24
25
26
27// index.php //
28/*===============================================================================*/
29
30<?php
31include_once 'dbconnect.php';
32
33// fetch files
34$sql = "select filename from tbl_files";
35$result = mysqli_query($con, $sql);
36?>
37
38<!DOCTYPE html>
39<html>
40<head>
41 <title>Private Server Access</title>
42 <meta content="width=device-width, initial-scale=1.0" name="viewport" >
43 <link rel="stylesheet" href="css/bootstrap.css" type="text/css" />
44</head>
45<body>
46<br/>
47<div class="container">
48 <div class="row">
49 <div class="col-xs-8 col-xs-offset-2 well">
50 <form action="uploads.php" method="post" enctype="multipart/form-data">
51 <legend>Select File to Upload [10GB Max]:</legend>
52 <b>If something needs to be removed let Alex know, as it's done from the back end.</b>
53 <br> <br>
54 <!-- <i>If the file has an invalid extension, place it in a .ZIP file or something?</i>
55 <p></p>
56 <i>Currently accepted formats: pdf, txt, doc, docx, png, jpg, jpeg, gif, mp4, avi, mp3, zip, rar, & jar</i>
57 <p></p> -->
58 <div class="form-group">
59 <input type="file" name="file1" />
60 </div>
61 <div class="form-group">
62 <input type="submit" name="submit" value="Upload" class="btn btn-info"/>
63 </div>
64 <?php if(isset($_GET['st'])) { ?>
65 <div class="alert alert-danger text-center">
66 <?php if ($_GET['st'] == 'success') {
67 echo "File Uploading Successfully!";
68 }
69 else
70 {
71 echo 'Invalid File Extension!';
72 } ?>
73 </div>
74 <?php } ?>
75 </form>
76 </div>
77 </div>
78
79 <div class="row">
80 <div class="col-xs-8 col-xs-offset-2">
81 <table class="table table-striped table-hover">
82 <thead>
83 <tr>
84 <th>#</th>
85 <th>File Name</th>
86 <th>View</th>
87 <th>Download</th>
88 </tr>
89 </thead>
90 <tbody>
91 <?php
92 $i = 1;
93 while($row = mysqli_fetch_array($result)) { ?>
94 <tr>
95 <td><?php echo $i++; ?></td>
96 <td><?php echo $row['filename']; ?></td>
97 <td><a href="uploads/<?php echo $row['filename']; ?>" target="_blank">View</a></td>
98 <td><a href="uploads/<?php echo $row['filename']; ?>" download>Download</td>
99 </tr>
100 <?php } ?>
101 </tbody>
102 </table>
103 </div>
104 </div>
105</div>
106</body>
107</html>
108
109
110
111// dbconnect.php //
112/*===============================================================================*/
113
114<?php
115//connect mysql database
116$host = "localhost";
117$user = "__________";
118$pass = "__________";
119$db = "demo";
120$con = mysqli_connect($host, $user, $pass, $db) or die("Error " . mysqli_error($con));
121?>
122
123
124
125// uploads.php //
126/*===============================================================================*/
127
128<?php
129include_once 'dbconnect.php';
130
131//check if form is submitted
132if (isset($_POST['submit']))
133{
134 $filename = $_FILES['file1']['name'];
135 //upload file
136 if($filename != '')
137 {
138 $trueCheck = true;
139 $ext = pathinfo($filename, PATHINFO_EXTENSION);
140 $allowed = ['pdf', 'txt', 'doc', 'docx', 'png', 'jpg', 'jpeg', 'gif', 'mp4', 'avi', 'mp3', 'zip', 'rar', 'jar'];
141
142 //check if file type is valid
143 if ($trueCheck == true) //If you want to turn on file restrictions, replace ($trueCheck == true) with (in_array($ext, $allowed)) and delete line #11
144 {
145 // get last record id
146 $sql = 'select max(id) as id from tbl_files';
147 $result = mysqli_query($con, $sql);
148 if (count($result) > 0)
149 {
150 $row = mysqli_fetch_array($result);
151 $filename = ($row['id']+1) . '-' . $filename;
152 }
153 else
154 $filename = '1' . '-' . $filename;
155
156 //set target directory
157 $path = 'uploads/';
158
159 $created = @date('Y-m-d H:i:s');
160 move_uploaded_file($_FILES['file1']['tmp_name'],($path . $filename));
161
162 // insert file details into database
163 $sql = "INSERT INTO tbl_files(filename, created) VALUES('$filename', '$created')";
164 mysqli_query($con, $sql);
165 header("Location: index.php?st=success");
166 }
167 else
168 {
169 header("Location: index.php?st=error");
170 }
171 }
172 else
173 header("Location: index.php");
174}
175?>