-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupload.php
executable file
·68 lines (59 loc) · 2.05 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
<?php
error_reporting(~E_ALL);
$tokens = array("uhotiasked"); // Tokens go here
$allowedFiles = array("png", "jpg", "gif", "txt", "jpeg", "mp4", "webm");
$sharexdir = "./"; // File directory
$lengthofstring = 3; // Length of file name
$json = new StdClass();
// Random file name generation
function RandomString($length) {
$keys = array_merge(range(0,9), range('a', 'z'));
$key = "";
for($i=0; $i < $length; $i++) {
$key .= $keys[mt_rand(0, count($keys) - 1)];
}
return $key;
}
// Check for token
/* if(isset($_POST['secret']))
{
// Checks if token is valid
if(in_array($_POST['secret'], $tokens))
{ */
// Prepares for upload
$filename = RandomString($lengthofstring);
$target_file = $_FILES["sharex"]["name"];
$fileType = pathinfo($target_file, PATHINFO_EXTENSION);
// Check if mime type is listed
if(!in_array($fileType, $allowedFiles)) {
http_response_code(406); // Return 406 Not Acceptable status code
$json->status = "Failed";
$json->errormsg = "This filetype is not allowed!";
// Accepts and moves to directory
} else if (move_uploaded_file($_FILES["sharex"]["tmp_name"], $sharexdir.$filename.'.'.$fileType)) {
//Sends info to client
$json->status = "OK";
$json->errormsg = null;
$json->url = $filename;
} else {
// Warning
http_response_code(400); // Return 400 Bad Request status code
$json->status = "Failed";
$json->errormsg = "File upload failed - CHMOD/Folder doesn\'t exist?";
}
/* } else {
// Invalid key
http_response_code(401); // Return 401 Unauthorized status code
$json->status = "Failed";
$json->errormsg = "Invalid Secret Key";
}
} else {
// Warning if no uploaded data
http_response_code(400); // Return 400 Bad Request status code
$json->status = "Failed";
$json->errormsg = "No post data recieved'";
}
*/
// Sends json
echo(json_encode($json));
?>