forked from nihalsrivastava02/Hackathon-2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuploadfile.php
More file actions
55 lines (46 loc) · 1.73 KB
/
uploadfile.php
File metadata and controls
55 lines (46 loc) · 1.73 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
<?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
{
$newfilename= date('dmYHis').str_replace(" ", "", basename($_FILES["fileToUpload"]["name"]));
// $withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $newfilename);
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 `assignment`(`subject_id`, `assignment_name`, `date_time`) VALUES ('$subject_id','$newfilename','$date')";
mysqli_query($conn,$sql);
echo $newfilename;
$q ='CREATE TABLE `'.$newfilename.'` (student_id VARCHAR(50), assignment_name VARCHAR(100), marks INT, date_time DATETIME);';
echo $q;
mysqli_query($conn, $q);
}
else
{
echo "Sorry, there was an error uploading your file.";
}
}
?>