-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
70 lines (64 loc) · 1.96 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
include 'setup.php';
$loc = "doc/";
$fname = basename($_FILES["file"]["name"]);
$newloc = $loc . $fname;
$filetype = pathinfo($newloc,PATHINFO_EXTENSION);
if(isset($_POST["submit"])){
$allowtypes = array('pdf');
if(in_array($filetype, $allowtypes)){
if(move_uploaded_file($_FILES["file"]["tmp_name"], $newloc)){
$sql = mysqli_query($conn, "INSERT into docs (file_name, uploaded_on) VALUES ('".$fname."', NOW())");
if($sql){
$msg = "file ".$fname. " uploaded";
}
}
}else{
$msg = 'only PDF allowed.';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>file module</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/main.css">
</head>
<body>
<fieldset style="margin: 50px; padding: 20px">
<legend>Upload PDF</legend>
<form action="index.php" method="post" enctype="multipart/form-data">
Select File to Upload:
<input type="file" name="file"><br>
<input type="submit" name="submit" value="Upload">
</form>
<?php
echo $msg;
?>
</fieldset>
<fieldset style="margin: 50px; padding: 20px">
<legend>Download PDFs</legend>
<?php
include 'setup.php';
$sql= "SELECT * FROM docs";
$result = mysqli_query($conn, $sql);
echo "<table class='table ver1'>";
echo'<th>ID</th><th>File name</th><th>Size (KB)</th><th>No. of downloads</th><th>Link</th>';
while($data = mysqli_fetch_array($result))
{
$id=$data['id'];
$file_name= $data['file_name'];
$path= "doc/". $file_name;
$size= filesize($path)/1024;
$size1= round($size, 3);
echo"<tr class='row'>";
echo '<td>'.$data['id'].'</td><td>'.$data['file_name'].'</td><td>'.$size1.'</td><td>'.$data['count'].'</td><td>'."<a href='download.php?down=$id'>download</a>".'</td>';
echo'</tr>';
}
echo "</table>";
?>
</fieldset>
</body>
</html>