-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuploadmaterialsdb.php
More file actions
62 lines (53 loc) · 2.28 KB
/
uploadmaterialsdb.php
File metadata and controls
62 lines (53 loc) · 2.28 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
54
55
56
57
58
59
60
61
62
<?php
session_start();
if(isset($_SESSION['facname']) && isset($_SESSION['facpswd']))
{
$user=$_SESSION['facname'];
$pass=$_SESSION['facpswd'];
}
else
{
echo '<script>alert("please login")</script>';
echo '<META http-equiv="refresh" content="0;logout.php">';
}
include 'dbconfigg.php';
$records = mysqli_query($conn, "SELECT * FROM `facultydetails` where username='$user'"); // fetch data from database
while ($row = mysqli_fetch_array($records)) {
$course=$row['course'];
}
// connect to the database
// Uploads files
if (isset($_POST['upload'])) { // if save button on the form is clicked
// name of the uploaded file
$filename = $_FILES['myfile']['name'];
// destination of the file on the server
$destination = 'materials/' . $filename;
// get the file extension
$extension = pathinfo($filename, PATHINFO_EXTENSION);
// the physical file on a temporary uploads directory on the server
$file = $_FILES['myfile']['tmp_name'];
$size = $_FILES['myfile']['size'];
echo $size;
if (!in_array($extension, ['zip', 'pdf', 'docx'])) {
echo '<script type="text/javascript">alert("You file extension must be .zip, .pdf or .docx")</script>';
echo '<meta http-equiv="refresh" content="0;addmaterials.php"/>';
}
//limiting post method for 2MB
else if($size >2000000){
echo '<script type="text/javascript">alert("You file must be less than 2MB")</script>';
echo '<meta http-equiv="refresh" content="0;addmaterials.php"/>';
}
else {
// move the uploaded (temporary) file to the specified destination
if (move_uploaded_file($file, $destination)) {
$sql = "INSERT INTO $course (name, size, downloads) VALUES ('$filename', $size, 0)";
if (mysqli_query($conn, $sql)) {
echo '<script type="text/javascript">alert(" File uploaded successfully")</script>';
echo '<meta http-equiv="refresh" content="0;addmaterials.php"/>';
}
} else {
echo '<script type="text/javascript">alert("Failed to upload file.")</script>';
echo '<meta http-equiv="refresh" content="0;addmaterials.php"/>';
}
}
}