|
|
|
|
|
|
23
|
}
|
23
|
}
|
|
24
|
|
24
|
|
|
25
|
public static function handleUpload($file = false) {
|
25
|
public static function handleUpload($file = false) {
|
|
|
|
26
|
+ $cwd = getcwd(); // Our websites CWD (Current working dir)
|
|
26
|
$filename = $file['name']; // Get filename
|
27
|
$filename = $file['name']; // Get filename
|
|
27
|
$size = $file['size']; // Gets filesize
|
28
|
$size = $file['size']; // Gets filesize
|
|
28
|
$tempname = $file['tmp_name']; // Where did php upload our data to?
|
29
|
$tempname = $file['tmp_name']; // Where did php upload our data to?
|
|
|
|
|
|
|
30
|
$ext = explode('.', $file['name']); // end() doesnt like us using explode directly.
|
31
|
$ext = explode('.', $file['name']); // end() doesnt like us using explode directly.
|
|
31
|
$extension = strtolower(end($ext)); // Get the extension of the file.
|
32
|
$extension = strtolower(end($ext)); // Get the extension of the file.
|
|
32
|
$randomname = Upload::generateRandomString(); // We give our file a random name - It will be this.
|
33
|
$randomname = Upload::generateRandomString(); // We give our file a random name - It will be this.
|
|
33
|
-
|
|
|
|
34
|
- $cwd = getcwd(); // Our websites CWD (Current working dir)
|
|
|
|
|
|
34
|
+
|
|
|
|
35
|
+ // If filename exists, we roll a new one.
|
|
|
|
36
|
+ while (IS_FILE($cwd .'/'. Config::$file_path . $randomname . '.' . $extension)) {
|
|
|
|
37
|
+ $randomname = Upload::generateRandomString();
|
|
|
|
38
|
+ }
|
|
|
|
39
|
+
|
|
|
|
40
|
+ // We got our unique filename, lets continue.
|
|
|
|
41
|
+
|
|
35
|
$uploadPath = $cwd .'/'. Config::$file_path . $randomname . '.' . $extension;
|
42
|
$uploadPath = $cwd .'/'. Config::$file_path . $randomname . '.' . $extension;
|
|
36
|
|
43
|
|
|
37
|
if (!in_array($extension, Config::$file_types)) {
|
44
|
if (!in_array($extension, Config::$file_types)) {
|