-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathuploadMul.php
More file actions
91 lines (86 loc) · 3.45 KB
/
uploadMul.php
File metadata and controls
91 lines (86 loc) · 3.45 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
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
<?php
if(isset($_POST['submit'])){
//Get the content of memCap.dat file which contains the maximus strage
//limit which is set by the admin
$capFile = fopen("src/set/memCap.dat", "r") or die("Unable to open file!");
$cap = fread($capFile,filesize("src/set/memCap.dat"));
fclose($capFile);
//Get the current folder size
function folderSize ($dir){
$size = 0;
foreach (glob(rtrim($dir, '/').'/*', GLOB_NOSORT) as $each) {
$size += is_file($each) ? filesize($each) : folderSize($each);
}
return $size;
}
$dirSize = (folderSize("uploads/")/1024)/1024/1024;
$precision = 2;
$dirSize = substr(number_format($dirSize, $precision+1, '.', ''), 0, -1);
//Get the total file size of files being uploaded (in GB)
$uploadSize = 0;
if(count($_FILES['upload']['name']) > 0){
for($i=0; $i<count($_FILES['upload']['name']); $i++) {
$fSize = $_FILES['upload']['size'][$i]/1024/1024/1024;
$uploadSize = $uploadSize + $fSize;
}
}
else{
//Redirect to home page
header('Location: index.php');
}
//Add current folder size and the size of the file being uploaded
//The size is in GB to match with storage cap set by admin
$totSize = $uploadSize + $dirSize;
//If the total size is less than the cap set
//Files can be uploaded
if($totSize<=$cap){
//Upload the files
//Get each files
$failUpload = 0;
for($i=0; $i<count($_FILES['upload']['name']); $i++) {
$file_name = $_FILES['upload']['name'][$i];
$file_tmp = $_FILES['upload']['tmp_name'][$i];
$file_size = $_FILES['upload']['size'][$i];
$file_error = $_FILES['upload']['error'][$i];
$file_dir = "uploads/oth/";
$file_ext = explode('.', $file_name);
$file_ext = strtolower(end($file_ext));
//Prevent upload of certain files that can cause security issues
if($file_ext=="php" || $file_ext=="html"){
$failUpload++;
continue;
}
else{
$file_error = 0;
if($file_error === 0) {
if($file_ext == "png" || $file_ext == "jpg" ||$file_ext == "jpeg" ||$file_ext == "gif" ||$file_ext == "bmp"){
$file_dir = "uploads/img/";
}
elseif ($file_ext == "mp4" ||$file_ext == "avi" ||$file_ext == "mkv" ||$file_ext == "mpeg" ||$file_ext == "mov") {
$file_dir = "uploads/vid/";
}
elseif ($file_ext == "mp3" ||$file_ext == "flac") {
$file_dir = "uploads/aud/";
}
$file_destination = $file_dir . $file_name;
if(move_uploaded_file($file_tmp, $file_destination)) {
continue;
}
else
$failUpload++;
}
}
}
//Redirect to home page
if($failUpload>0)
header('Location: index.php?e=1');
else
header('Location: index.php');
//header('Location: index.php');
}
//Storage cap exceeded. Error message is shown
else{
echo "Storage limit exceeded! Delete some files or increase the storage limit from dashboard.";
}
}
?>