-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileslogic.php
65 lines (55 loc) · 1.71 KB
/
fileslogic.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
<html>
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
</head>
</html>>
<?php
// connect to the database
session_start();
$conn = mysqli_connect('localhost', 'root', '', 'dept_portal');
$sql = "SELECT * FROM files";
$result = mysqli_query($conn, $sql);
$files = mysqli_fetch_all($result, MYSQLI_ASSOC);
require_once 'config.php';
if(isset($_POST['save']))
{
$cid=$_SESSION['cid'];
$name=$_FILES['myfile']['name'];
$type=$_FILES['myfile']['type'];
$data= file_get_contents($_FILES['myfile']['tmp_name']);
$date=$_POST['date'];
$extension = pathinfo($name, PATHINFO_EXTENSION);
$url='document_upload.php';
if (!in_array($extension, ['zip', 'pdf', 'docx','pptx']))
{
echo "You file extension must be .zip, .pptx, .pdf or .docx";
}
elseif ($_FILES['myfile']['size'] >10000000)
{ // file shouldn't be larger than 1Megabyte
echo "File too large!";
}
else
{
$stmt=$dbhandler->prepare("insert into Document values('',?,?,?,?,?)");
$stmt->bindParam(1,$cid);
$stmt->bindParam(2,$name);
$stmt->bindParam(3,$type);
$stmt->bindParam(4,$data);
$stmt->bindParam(5,$date);
$stmt->execute();
if($stmt)
{
echo "<div class='alert alert-success' role='alert' style='margin:50px;'>
Document uploaded successfully!
</div>";
}
else
{
echo "<div class='alert alert-warning' role='alert'>
Something went wrong. Please check it out!
</div>";
}
}
}
?>