-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsubmit.php
More file actions
42 lines (35 loc) · 1.49 KB
/
submit.php
File metadata and controls
42 lines (35 loc) · 1.49 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
<?php
session_start();
error_reporting(E_ERROR | E_PARSE);
// If the session vars aren't set, try to set them with a cookie
if (!isset($_SESSION['user_id'])) {
if (isset($_COOKIE['user_id']) && isset($_COOKIE['username'])) {
$_SESSION['user_id'] = $_COOKIE['user_id'];
$_SESSION['username'] = $_COOKIE['username'];
}
}
?>
<?php
if(!empty($_FILES['file']['name'])){
$uploadedFile = '';
if(!empty($_FILES["file"]["type"])){
$fileName = $_FILES['file']['name'];
$valid_extensions = array("jpeg", "jpg", "png");
$temporary = explode(".", $_FILES["file"]["name"]);
$file_extension = end($temporary);
//echo $_FILES["file"]["type"];
if((($_FILES["file"]["type"] == "application/pdf"))){
$sourcePath = $_FILES['file']['tmp_name'];
$targetPath = "uploads/".$fileName;
if(move_uploaded_file($sourcePath,$targetPath)){
$uploadedFile = $fileName;
}
}
}
}
//include database configuration file
$mysqli = new mysqli("localhost", "root", "", "linust_f");
$insert = "INSERT INTO file_upload (user_id,course_name,file_name,f_date) VALUES ('".$_SESSION['user_id']."', 'dbs','".$uploadedFile."', curdate())";
$answer = mysqli_query($mysqli, $insert);
mysqli_query($mysqli, "UPDATE users SET no_of_uploads=no_of_uploads+1 WHERE user_id='".$_SESSION['user_id']."'");
echo $answer?'ok':'Try Again';