cleanup how time taken works
This commit is contained in:
parent
3ef5a5023e
commit
bdf583f21f
32
upload.php
32
upload.php
@ -37,6 +37,15 @@ function generateRandomString($length = 10): string
|
|||||||
return $randomString;
|
return $randomString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the time taken to execute the script
|
||||||
|
*/
|
||||||
|
function getTimeTaken()
|
||||||
|
{
|
||||||
|
global $before;
|
||||||
|
return round(microtime(true) - $before, 3) . "ms";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a JSON response
|
* Return a JSON response
|
||||||
*/
|
*/
|
||||||
@ -52,23 +61,22 @@ try {
|
|||||||
|
|
||||||
// Check if the token is valid
|
// Check if the token is valid
|
||||||
if (!checkToken($token)) {
|
if (!checkToken($token)) {
|
||||||
$timeTaken = microtime(true) - $before;
|
|
||||||
returnJson(array(
|
returnJson(array(
|
||||||
'status' => 'ERROR',
|
'status' => 'ERROR',
|
||||||
'message' => 'Invalid token',
|
'message' => 'Invalid or missing upload secret',
|
||||||
|
// Remove this if you don't want to show the support URL
|
||||||
'support' => "For support, visit - https://git.fascinated.cc/Fascinated/sharex-php-uploader",
|
'support' => "For support, visit - https://git.fascinated.cc/Fascinated/sharex-php-uploader",
|
||||||
'timeTaken' => $timeTaken
|
'timeTaken' => getTimeTaken()
|
||||||
));
|
));
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the file was uploaded
|
// Check if the file was uploaded
|
||||||
if (!isset($file)) {
|
if (!isset($file)) {
|
||||||
$timeTaken = microtime(true) - $before;
|
|
||||||
returnJson(array(
|
returnJson(array(
|
||||||
'status' => 'ERROR',
|
'status' => 'ERROR',
|
||||||
'message' => 'No file was uploaded',
|
'message' => 'No file was uploaded',
|
||||||
'timeTaken' => $timeTaken
|
'timeTaken' => getTimeTaken()
|
||||||
));
|
));
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
@ -78,11 +86,10 @@ try {
|
|||||||
|
|
||||||
// Check if the file already exists
|
// Check if the file already exists
|
||||||
if (file_exists($uploadDir . $target_file)) {
|
if (file_exists($uploadDir . $target_file)) {
|
||||||
$timeTaken = microtime(true) - $before;
|
|
||||||
returnJson(array(
|
returnJson(array(
|
||||||
'status' => 'ERROR',
|
'status' => 'ERROR',
|
||||||
'message' => 'File already exists',
|
'message' => 'File already exists',
|
||||||
'timeTaken' => $timeTaken
|
'timeTaken' => getTimeTaken()
|
||||||
));
|
));
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
@ -106,18 +113,16 @@ try {
|
|||||||
if ($shouldSave) {
|
if ($shouldSave) {
|
||||||
// Move the file to the uploads folder
|
// Move the file to the uploads folder
|
||||||
if (move_uploaded_file($_FILES["sharex"]["tmp_name"], $uploadDir . $finalName)) {
|
if (move_uploaded_file($_FILES["sharex"]["tmp_name"], $uploadDir . $finalName)) {
|
||||||
$timeTaken = microtime(true) - $before;
|
|
||||||
returnJson(array(
|
returnJson(array(
|
||||||
'status' => 'OK',
|
'status' => 'OK',
|
||||||
'message' => 'File uploaded successfully',
|
'message' => 'File uploaded successfully',
|
||||||
'timeTaken' => $timeTaken
|
'timeTaken' => getTimeTaken()
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
$timeTaken = microtime(true) - $before;
|
|
||||||
returnJson(array(
|
returnJson(array(
|
||||||
'status' => 'ERROR',
|
'status' => 'ERROR',
|
||||||
'message' => 'Failed to save file. Check the permissions of the upload directory.',
|
'message' => 'Failed to save file. Check the permissions of the upload directory.',
|
||||||
'timeTaken' => $timeTaken
|
'timeTaken' => getTimeTaken()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
die();
|
die();
|
||||||
@ -125,15 +130,14 @@ try {
|
|||||||
returnJson(array(
|
returnJson(array(
|
||||||
'status' => 'OK',
|
'status' => 'OK',
|
||||||
'message' => 'File uploaded successfully',
|
'message' => 'File uploaded successfully',
|
||||||
'timeTaken' => $timeTaken
|
'timeTaken' => getTimeTaken()
|
||||||
));
|
));
|
||||||
die();
|
die();
|
||||||
} catch (Exception $e) { // Handle any errors
|
} catch (Exception $e) { // Handle any errors
|
||||||
$timeTaken = microtime(true) - $before;
|
|
||||||
returnJson(array(
|
returnJson(array(
|
||||||
'status' => 'ERROR',
|
'status' => 'ERROR',
|
||||||
'message' => $e->getMessage(),
|
'message' => $e->getMessage(),
|
||||||
'timeTaken' => $timeTaken
|
'timeTaken' => getTimeTaken()
|
||||||
));
|
));
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user