forked from gitbot/uguu
commit
6b29b776ab
@ -130,8 +130,11 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
} else if (respStatus === 413) {
|
} else if (respStatus === 413) {
|
||||||
link.textContent = 'File too big!';
|
link.textContent = 'File too big!';
|
||||||
url.appendChild(link);
|
url.appendChild(link);
|
||||||
|
} else if (respStatus === 415) {
|
||||||
|
link.textContent = 'Filetype not allowed!';
|
||||||
|
url.appendChild(link);
|
||||||
} else {
|
} else {
|
||||||
link.textContent = 'Filetype not allowed or server error!';
|
link.textContent = 'Server error!';
|
||||||
url.appendChild(link);
|
url.appendChild(link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ class Response
|
|||||||
*
|
*
|
||||||
* Valid strings are 'csv', 'html', 'json' and 'text'.
|
* Valid strings are 'csv', 'html', 'json' and 'text'.
|
||||||
*
|
*
|
||||||
* @var string $type Response type
|
* @var string Response type
|
||||||
*/
|
*/
|
||||||
private $type;
|
private $type;
|
||||||
|
|
||||||
@ -57,8 +57,9 @@ class Response
|
|||||||
/**
|
/**
|
||||||
* Routes error messages depending on response type.
|
* Routes error messages depending on response type.
|
||||||
*
|
*
|
||||||
* @param int $code HTTP status code number.
|
* @param int $code HTTP status code number
|
||||||
* @param int $desc Descriptive error message.
|
* @param int $desc descriptive error message
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function error($code, $desc)
|
public function error($code, $desc)
|
||||||
@ -80,7 +81,7 @@ class Response
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
http_response_code(500); // "500 Internal Server Error"
|
//http_response_code(500); // "500 Internal Server Error"
|
||||||
echo $response;
|
echo $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,6 +89,7 @@ class Response
|
|||||||
* Routes success messages depending on response type.
|
* Routes success messages depending on response type.
|
||||||
*
|
*
|
||||||
* @param mixed[] $files
|
* @param mixed[] $files
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function send($files)
|
public function send($files)
|
||||||
@ -117,8 +119,10 @@ class Response
|
|||||||
* Indicates with CSV body the request was invalid.
|
* Indicates with CSV body the request was invalid.
|
||||||
*
|
*
|
||||||
* @deprecated 2.1.0 Will be renamed to camelCase format.
|
* @deprecated 2.1.0 Will be renamed to camelCase format.
|
||||||
* @param int $description Descriptive error message.
|
*
|
||||||
* @return string Error message in CSV format.
|
* @param int $description descriptive error message
|
||||||
|
*
|
||||||
|
* @return string error message in CSV format
|
||||||
*/
|
*/
|
||||||
private static function csvError($description)
|
private static function csvError($description)
|
||||||
{
|
{
|
||||||
@ -129,8 +133,10 @@ class Response
|
|||||||
* Indicates with CSV body the request was successful.
|
* Indicates with CSV body the request was successful.
|
||||||
*
|
*
|
||||||
* @deprecated 2.1.0 Will be renamed to camelCase format.
|
* @deprecated 2.1.0 Will be renamed to camelCase format.
|
||||||
|
*
|
||||||
* @param mixed[] $files
|
* @param mixed[] $files
|
||||||
* @return string Success message in CSV format.
|
*
|
||||||
|
* @return string success message in CSV format
|
||||||
*/
|
*/
|
||||||
private static function csvSuccess($files)
|
private static function csvSuccess($files)
|
||||||
{
|
{
|
||||||
@ -149,9 +155,11 @@ class Response
|
|||||||
* Indicates with HTML body the request was invalid.
|
* Indicates with HTML body the request was invalid.
|
||||||
*
|
*
|
||||||
* @deprecated 2.1.0 Will be renamed to camelCase format.
|
* @deprecated 2.1.0 Will be renamed to camelCase format.
|
||||||
* @param int $code HTTP status code number.
|
*
|
||||||
* @param int $description Descriptive error message.
|
* @param int $code HTTP status code number
|
||||||
* @return string Error message in HTML format.
|
* @param int $description descriptive error message
|
||||||
|
*
|
||||||
|
* @return string error message in HTML format
|
||||||
*/
|
*/
|
||||||
private static function htmlError($code, $description)
|
private static function htmlError($code, $description)
|
||||||
{
|
{
|
||||||
@ -162,8 +170,10 @@ class Response
|
|||||||
* Indicates with HTML body the request was successful.
|
* Indicates with HTML body the request was successful.
|
||||||
*
|
*
|
||||||
* @deprecated 2.1.0 Will be renamed to camelCase format.
|
* @deprecated 2.1.0 Will be renamed to camelCase format.
|
||||||
|
*
|
||||||
* @param mixed[] $files
|
* @param mixed[] $files
|
||||||
* @return string Success message in HTML format.
|
*
|
||||||
|
* @return string success message in HTML format
|
||||||
*/
|
*/
|
||||||
private static function htmlSuccess($files)
|
private static function htmlSuccess($files)
|
||||||
{
|
{
|
||||||
@ -180,41 +190,47 @@ class Response
|
|||||||
* Indicates with JSON body the request was invalid.
|
* Indicates with JSON body the request was invalid.
|
||||||
*
|
*
|
||||||
* @deprecated 2.1.0 Will be renamed to camelCase format.
|
* @deprecated 2.1.0 Will be renamed to camelCase format.
|
||||||
* @param int $code HTTP status code number.
|
*
|
||||||
* @param int $description Descriptive error message.
|
* @param int $code HTTP status code number
|
||||||
* @return string Error message in pretty-printed JSON format.
|
* @param int $description descriptive error message
|
||||||
|
*
|
||||||
|
* @return string error message in pretty-printed JSON format
|
||||||
*/
|
*/
|
||||||
private static function jsonError($code, $description)
|
private static function jsonError($code, $description)
|
||||||
{
|
{
|
||||||
return json_encode(array(
|
return json_encode([
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'errorcode' => $code,
|
'errorcode' => $code,
|
||||||
'description' => $description,
|
'description' => $description,
|
||||||
), JSON_PRETTY_PRINT);
|
], JSON_PRETTY_PRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates with JSON body the request was successful.
|
* Indicates with JSON body the request was successful.
|
||||||
*
|
*
|
||||||
* @deprecated 2.1.0 Will be renamed to camelCase format.
|
* @deprecated 2.1.0 Will be renamed to camelCase format.
|
||||||
|
*
|
||||||
* @param mixed[] $files
|
* @param mixed[] $files
|
||||||
* @return string Success message in pretty-printed JSON format.
|
*
|
||||||
|
* @return string success message in pretty-printed JSON format
|
||||||
*/
|
*/
|
||||||
private static function jsonSuccess($files)
|
private static function jsonSuccess($files)
|
||||||
{
|
{
|
||||||
return json_encode(array(
|
return json_encode([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'files' => $files,
|
'files' => $files,
|
||||||
), JSON_PRETTY_PRINT);
|
], JSON_PRETTY_PRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates with plain text body the request was invalid.
|
* Indicates with plain text body the request was invalid.
|
||||||
*
|
*
|
||||||
* @deprecated 2.1.0 Will be renamed to camelCase format.
|
* @deprecated 2.1.0 Will be renamed to camelCase format.
|
||||||
* @param int $code HTTP status code number.
|
*
|
||||||
* @param int $description Descriptive error message.
|
* @param int $code HTTP status code number
|
||||||
* @return string Error message in plain text format.
|
* @param int $description descriptive error message
|
||||||
|
*
|
||||||
|
* @return string error message in plain text format
|
||||||
*/
|
*/
|
||||||
private static function textError($code, $description)
|
private static function textError($code, $description)
|
||||||
{
|
{
|
||||||
@ -225,8 +241,10 @@ class Response
|
|||||||
* Indicates with plain text body the request was successful.
|
* Indicates with plain text body the request was successful.
|
||||||
*
|
*
|
||||||
* @deprecated 2.1.0 Will be renamed to camelCase format.
|
* @deprecated 2.1.0 Will be renamed to camelCase format.
|
||||||
|
*
|
||||||
* @param mixed[] $files
|
* @param mixed[] $files
|
||||||
* @return string Success message in plain text format.
|
*
|
||||||
|
* @return string success message in plain text format
|
||||||
*/
|
*/
|
||||||
private static function textSuccess($files)
|
private static function textSuccess($files)
|
||||||
{
|
{
|
||||||
|
@ -56,12 +56,14 @@ function generateName($file)
|
|||||||
|
|
||||||
//Check if mime is blacklisted
|
//Check if mime is blacklisted
|
||||||
if (in_array($type_mime, unserialize(CONFIG_BLOCKED_MIME))) {
|
if (in_array($type_mime, unserialize(CONFIG_BLOCKED_MIME))) {
|
||||||
|
http_response_code(415);
|
||||||
throw new Exception('Filetype not allowed!');
|
throw new Exception('Filetype not allowed!');
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if EXT is blacklisted
|
//Check if EXT is blacklisted
|
||||||
if (in_array($ext, unserialize(CONFIG_BLOCKED_EXTENSIONS))) {
|
if (in_array($ext, unserialize(CONFIG_BLOCKED_EXTENSIONS))) {
|
||||||
|
http_response_code(415);
|
||||||
throw new Exception('Filetype not allowed!');
|
throw new Exception('Filetype not allowed!');
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
@ -103,6 +105,7 @@ function uploadFile($file)
|
|||||||
|
|
||||||
// Attempt to move it to the static directory
|
// Attempt to move it to the static directory
|
||||||
if (!move_uploaded_file($file->tempfile, $uploadFile)) {
|
if (!move_uploaded_file($file->tempfile, $uploadFile)) {
|
||||||
|
http_response_code(500);
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
'Failed to move file to destination',
|
'Failed to move file to destination',
|
||||||
500
|
500
|
||||||
@ -111,6 +114,7 @@ function uploadFile($file)
|
|||||||
|
|
||||||
// Need to change permissions for the new file to make it world readable
|
// Need to change permissions for the new file to make it world readable
|
||||||
if (!chmod($uploadFile, 0644)) {
|
if (!chmod($uploadFile, 0644)) {
|
||||||
|
http_response_code(500);
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
'Failed to change file permissions',
|
'Failed to change file permissions',
|
||||||
500
|
500
|
||||||
|
Loading…
Reference in New Issue
Block a user