-
Notifications
You must be signed in to change notification settings - Fork 1
/
fileUpload.php
executable file
·117 lines (106 loc) · 3.63 KB
/
fileUpload.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
ob_clean();
ini_set('display_errors', 'On');
error_reporting(E_ALL);
require_once("util.php");
//define("DEFAULT_FILE_STORAGE_PATH", "/home/vadwebData/");
//definition of default storage moved to util
function error($eNum = NULL)
{
}
function rearrange( $arr )
{
foreach( $arr as $key => $all ){ //key is file param, all is array of params for all files
foreach( $all as $i => $val ){ //all is array of params for all files, I one param, val is param value
$new[$i][$key] = $val;
}
}
return $new;
}
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
if (!canUpload())
{
echo "E:UP_PERM<br>";
echo "LOOKS LIKE YOU NEED TO LOG IN OR REGISTER TO UPLOAD!";
return false;
}
if (uploadingCooldown() !== false)
{
echo "E:COOLDOWN<br>";
echo "You've uploaded too many files recently!!! Please wait for " . uploadingCooldown() . " (H:M:S) before trying again...";
return false;
}
$fileArr = array();
$onlyOneFile = isset($_FILES["fileSingle"]["name"])?1:0;
//echo $onlyOneFile . "<br><br>";
if (!$onlyOneFile)
{
$file_ary = rearrange($_FILES['fileMulti']);
foreach ($file_ary as $file)
{
//echo "Printing file data <br>";
//print_r($file);
$upFile = new UploadedFile($file['name'], $file['tmp_name'], $file['size'], $file['error'], $_POST["perm"], $_POST["otherPermData"], NULL); //here also pass POST[perm]\
//TODO this is broken with permissions and unlisted, sets the same permission for each file...
array_push($fileArr, $upFile);
}
}
else
{
$upFile = new UploadedFile($_FILES["fileSingle"]['name'], $_FILES["fileSingle"]['tmp_name'], $_FILES["fileSingle"]["size"], $_FILES["fileSingle"]['error'], $_POST["perm"], $_POST["otherPermData"], $_POST["fileDesc"]);
array_push($fileArr, $upFile);
}
if (count($fileArr) > Constants::MULTI_FILE_UPLOAD_NUM_LIMIT)
{
echo "E:NUM_FILES";
return false;
}
$redirect = true;
foreach ($fileArr as $key => $f)
{
//TODO WHEN FILES FAIL IT STILL REDIRECTS
//TODO Add authentication for canUpload
//TODO Actually figure out restrictions, who can do what with uploading
//TODO Add captcha
$f->validateFileForErrors();
if (isset($_POST["unlisted"]))
$f->setUnlisted();
if ($f->type == File::$types["MOVIE"])
{
echo "MOVIE!!! MAY TAKE TIME TO CONVERT";
}
$result = $f->storeFile();
if ($result !== true) {
$redirect = false;
}
//header("Refresh:30; URL=http://www.vadweb.us/files.php");
echo $result."<br>";
echo "<h1> ERROR!!! </h1>";
echo "Printing info for " . $key . ": <br>";
echo "     " . $f->name . "<br>";
echo "     " . $f->nameNoEXT . "<br>";
echo "     " . $f->extension . "<br>";
echo "     <h2> Please note this error code: " . $f->uploadError . "</h2><br>";
echo "     " . $f->type . "<br>";
echo "     " . $f->size . "<br>";
echo "     " . $f->absPath . "<br>";
echo "<br>";
if ($result > 0) {
echo "<strong> Successfully wrote to folder file number: " . $key . "</strong><br>";
echo "<a href='files.php'> Return to files page </a>";
}
/**some sort of file writing here that will store file in separate folder at /var/vadData (or something) and
* insert info about file as printed above into mysql
* MAKE SURE TO HANDLE ERRORS SOMEHOW (maybe as part of UploadedFile class) for custom errors, eg file name too long,
* multiple dots in file name etc
*/
}
if ($redirect)
{
ob_clean();
header("Location: /files.php?s=t");
}
gc_enable();
}
?>