-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsave_file.php
More file actions
50 lines (40 loc) · 1.52 KB
/
save_file.php
File metadata and controls
50 lines (40 loc) · 1.52 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
<?php // save assigment submited by student
require_once 'conn.php';
if(isset($_POST['save'])){
$c_id = $_POST['c_id']; // course id
$s_id = $_POST['s_id']; // stuent id
$s_name = $_POST['s_name']; // student name
$f_name = $_FILES['file']['name']; // file name
$f_type = $_FILES['file']['type']; // file type
$f_temp = $_FILES['file']['tmp_name']; // temp name of file
$location = "files/".$s_id."_".$s_name."/".$f_name; // location where file will save
$date = date("Y-m-d H:i:s"); // date of submited file
if(!file_exists("files/".$s_id."_".$s_name)){
mkdir("files/".$s_id."_".$s_name, 0777, true); // script for making nested directory
}
# check if file is pdf or not
if($f_type != "application/pdf"){
//header('location:student_profile.php');
echo "<script>
alert('Only Pdf file format is allowed.');
window.location.href='student_profile.php';
</script>";
} else {
# check if file already exists or not
if(file_exists($location)){
echo "<script>
alert('File already uploaded.');
window.location.href='student_profile.php';
</script>";
//header('location:student_profile.php');
} else {
# save file in folder and keep records in table
if(move_uploaded_file($f_temp, $location)){
$insert = "insert into storage values('','$f_name','$f_type','$date','$s_id','$s_name','$c_id')";
mysqli_query($con, $insert);
header('location:student_profile.php');
}
}
}
}
?>