-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.php
57 lines (46 loc) · 1.82 KB
/
upload.php
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
<?php
// Include database configuration file
require_once 'dbConfig.php';
$statusMsg = $valErr = '';
$status = 'danger';
// If the form is submitted
if(isset($_POST['submit'])){
// Validate form input fields
if(empty($_FILES["file"]["name"])){
$valErr .= 'Please select a file to upload.<br/>';
}
// Check whether user inputs are empty
if(empty($valErr)){
$targetDir = "uploads/";
$fileName = basename($_FILES["file"]["name"]);
$targetFilePath = $targetDir . $fileName;
// Upload file to local server
if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)){
// Insert data into the database
$sqlQ = "INSERT INTO drive_files (file_name,created) VALUES (?,NOW())";
$stmt = $db->prepare($sqlQ);
$stmt->bind_param("s", $db_file_name);
$db_file_name = $fileName;
$insert = $stmt->execute();
if($insert){
$file_id = $stmt->insert_id;
// Store DB reference ID of file in SESSION
$_SESSION['last_file_id'] = $file_id;
header("Location: $googleOauthURL");
exit();
}else{
$statusMsg = 'Something went wrong, please try again after some time.';
}
}else{
$statusMsg = 'File upload failed, please try again after some time.';
}
}else{
$statusMsg = '<p>Please fill all the mandatory fields:</p>'.trim($valErr, '<br/>');
}
}else{
$statusMsg = 'Form submission failed!';
}
$_SESSION['status_response'] = array('status' => $status, 'status_msg' => $statusMsg);
header("Location: index.php");
exit();
?>