forked from Nachomontoya/filesystem-explorer
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupload.php
More file actions
57 lines (44 loc) · 1.64 KB
/
Copy pathupload.php
File metadata and controls
57 lines (44 loc) · 1.64 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
<?php
$root = "./root/";
$path = $root.$_FILES['fileToUpload']['name'];
if (isset($_POST['submit'])) {
$file = $_FILES['fileToUpload'];
$fileName = $_FILES['fileToUpload']['name'];
$fileSize = $_FILES['fileToUpload']['size'];
$fileType = $_FILES['fileToUpload']['type'];
$fileError = $_FILES['fileToUpload']['error'];
$fileTmpName = $_FILES['fileToUpload']['tmp_name'];
$fileExt=explode('.',$fileName);
$fileActualExt=strtolower(end($fileExt));
$dateCreated = date("F d Y H:i:s.", filectime($fileTmpName));
$dateModified = date("F d Y H:i:s.", filemtime($fileTmpName));
if ($fileError === 0){
$fileDestination = $path;
echo __DIR__;
$file = array(
'name' => $fileName,
'ext' => $fileActualExt,
'root' => $fileDestination,
'size' => $fileSize,
'created' => $dateCreated,
'modified' => $dateModified
);
if(filesize("db.json") == 0){
$first_record = array($file);
$data_to_save = $first_record;
}else{
$old_records = json_decode(file_get_contents("db.json"));
array_push($old_records, $file);
$data_to_save = $old_records;
}
if(!file_put_contents("db.json", json_encode($data_to_save, JSON_PRETTY_PRINT))){
$error = "Error storing file, try again";
}else{
$success = "File is stored successfully";
}
move_uploaded_file($fileTmpName, $fileDestination);
header('location: index.php');
} else {
echo "There was an error uploading your file!";
}
}