-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.php
92 lines (90 loc) · 3.6 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
//upload procedure
require('inc/const.php');
if (isset($_POST['upload'])) {
$fileName = $_FILES["file"]["name"];
$fileTmpLoc = $_FILES["file"]["tmp_name"];
$fileType = $_FILES["file"]["type"];
$fileSize = $_FILES["file"]["size"];
$fileErrorMsg = $_FILES["file"]["error"];
$location = $_POST['subfolder'];
if (!$fileTmpLoc) {
header('location: ' . URL . '?page=0&sort=name&type=desc&folder=uploads/&message=nofile');
} elseif ($fileErrorMsg == 1) {
header('location: ' . URL . '?page=0&sort=name&type=desc&folder=uploads/&message=uploaderror');
} else {
//checking if subfolder directory exists
if (empty($location) || !isset($location) || $location === "" || $location === "uploads/") {
preg_match_all('/[A-Za-z0-1]*\.[a-zA-Z0-1]*/', $fileName, $matches);
$ext = end($matches);
$removed = array_pop($matches);
array_pop($removed);
$kek = implode($removed);
$deez = end($ext);
$i = 0;
$fn = $fileName;
if (count($removed)<=1) {
$exp = explode(".",$fileName);
$end = end($exp);
while (file_exists("uploads/".$fn)) {
$i++;
$fn = reset($exp)."_".$i.".".$end;
}
$name = $fn;
$moveResult = move_uploaded_file($fileTmpLoc, $location . "/". $name);
}else{
while (file_exists("uploads/".$fn)) {
$i++;
// add number to actual filename
$fn = $kek."_".$i.$deez;
}
$name = $fn;
$moveResult = move_uploaded_file($fileTmpLoc, "uploads/". $name);
}
if ($moveResult != true) {
@unlink($fileTmpLoc);
header('location: ' . URL . '?page=0&sort=name&type=desc&folder=uploads/&message=uploaderror');
}
header('location: ' . URL . '?page=0&sort=name&type=desc&folder=uploads/&message=success');
} else {
if (!is_dir("uploads/".$location)) {
header('location: ' . URL . '?page=0&sort=name&type=desc&folder=uploads/&message=FDE');
}
preg_match_all('/[A-Za-z0-1]*\.[a-zA-Z0-1]*/', $fileName, $matches);
$ext = end($matches);
$removed = array_pop($matches);
array_pop($removed);
$kek = implode($removed);
$deez = end($ext);
$i = 0;
$fn = $fileName;
if (count($removed)<=1) {
$exp = explode(".",$fileName);
$end = end($exp);
while (file_exists($location.$fn)) {
$i++;
$fn = reset($exp)."_".$i.".".$end;
}
$name = $fn;
$moveResult = move_uploaded_file($fileTmpLoc, $location . "/". $name);
}else{
while (file_exists($location.$fn)) {
$i++;
// add number to actual filename
$fn = $kek."_".$i.$deez;
}
$name = $fn;
$moveResult = move_uploaded_file($fileTmpLoc, $location . "/". $name);
}
if ($moveResult != true) {
@unlink($fileTmpLoc);
header('location: ' . URL . '?page=0&sort=name&type=desc&folder=uploads/&message=uploaderror');
exit();
}
header('location: ' . URL . '?page=0&sort=name&type=desc&folder='.$location.'&message=success');
exit();
}
}
} else {
header('location: ' . URL . '?page=0&sort=name&type=desc&folder=uploads/&message=UAC');
}