-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpload.php
More file actions
53 lines (48 loc) · 1.59 KB
/
Upload.php
File metadata and controls
53 lines (48 loc) · 1.59 KB
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
<?php
include 'Connection.php';
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if (isset($_POST['submit'])) {
$circu_name = $_POST['circu_name'];
$file = $_FILES['file'];
$fileName = $_FILES['file']['name'];
$fileTmpName = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileError = $_FILES['file']['error'];
$fileType = $_FILES['file']['type'];
$fileExt = explode('.',$fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array ('jpg','jpeg','png', 'pdf', 'docx');
if(in_array($fileActualExt,$allowed )){
if($fileError===0){
if($fileSize < 2000000){
$fileNameNew=uniqid('',true).".".$fileActualExt;
$fileDestination='uploads/'.$fileNameNew;
move_uploaded_file($fileTmpName,$fileDestination);
}else {
echo "File too large!";
}
}else {
echo "Failed to upload file.";
}
}else {
echo "You file extension must be .zip, .pdf or .docx";
}
$catagory = $_POST['catagory'];
$sem = $_POST['sem'];
$sql="INSERT INTO circulardb (C_NAME,FILE,CATAGORY,SEMESTER)
VALUES('" . $circu_name . "','" . $fileNameNew . "','" . $catagory . "','" . $sem . "')";
$result=$conn->query($sql);
if ($result === TRUE) {
echo "<script>alert('data is inserted successfully')</script>";
echo '<script>window.location="AdminDataManager.php"</script>';
} else {
echo "<script>alert('data is not inserted')</script>";
echo '<script>window.location="DataInsert.php"</script>';
}
}
?>