forked from nihalsrivastava02/Hackathon-2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent_assignment_upload.php
More file actions
71 lines (66 loc) · 2.12 KB
/
student_assignment_upload.php
File metadata and controls
71 lines (66 loc) · 2.12 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
63
64
65
66
67
68
69
70
71
<?php
error_reporting(E_ALL^E_NOTICE);
if(!$_SESSION['u_type']== 'S')
{
die("Invalid user");
}
?>
<?php
$target_dir = "assignment/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$filetype = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
session_start();
echo $_SESSION['assignment_id']." ";
$subject_id=$_SESSION['assignment_id'];
$date = date('Y-m-d H:i:s');
require_once("db_connection.php");
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Allow certain file formats
if($filetype != "docx" && $filetype != "doc" && $filetype != "pdf" && $filetype != "txt") {
echo "Sorry, only docx, doc, pdf & txt files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
}
else
{
$id=$_SESSION['u_name'];
$newfilename= date('dmYHis').str_replace(" ", "", basename($_FILES["fileToUpload"]["name"]));
$withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $newfilename);
$check="Select * from `".$subject_id."` where `student_id`='".$id."';";
//echo $check;
$result=mysqli_query($conn,$check);
$row=mysqli_fetch_array($result);
echo $row;
if(!$row)
{
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], "assignment/" . $newfilename))
{
$file_name=$_FILES["fileToUpload"]["name"];
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
$sql="INSERT INTO `".$subject_id."`(`student_id`, `assignment_name`,`marks`, `date_time`) VALUES ('$id','$newfilename','0','$date');";
echo $sql;
mysqli_query($conn,$sql);
echo $newfilename;
}
else
{
echo "Sorry, there was an error uploading your file.";
}
}
else
{
echo '<script language="javascript">';
echo 'alert("You have already uploaded assignment")';
echo '</script>';
}
}
?>