Fixed inaccurate message in case of file too large (fixes #15)

Minor fix to the mobile layout
This commit is contained in:
Sergio Brighenti 2019-01-24 11:49:46 +01:00
parent f49d6ef979
commit dbc55bdb6f
5 changed files with 44 additions and 2 deletions

View file

@ -1,3 +1,7 @@
## v2.4.1
+ Fixed error message when the file is too large. (#15)
+ Fixed button alignment.
## v2.4 ## v2.4
+ Added function to remove orphaned files. + Added function to remove orphaned files.
+ Switch between tab and gallery mode using an admin account. + Switch between tab and gallery mode using an admin account.

View file

@ -26,6 +26,16 @@ class UploadController extends Controller
$json = ['message' => null]; $json = ['message' => null];
if ($request->getServerParam('CONTENT_LENGTH') > stringToBytes(ini_get('post_max_size'))) {
$json['message'] = 'File too large (post_max_size too low).';
return $response->withJson($json, 400);
}
if ($request->getUploadedFiles()['upload']->getError() === UPLOAD_ERR_INI_SIZE) {
$json['message'] = 'File too large (upload_max_filesize too low).';
return $response->withJson($json, 400);
}
if ($request->getParam('token') === null) { if ($request->getParam('token') === null) {
$json['message'] = 'Token not specified.'; $json['message'] = 'Token not specified.';
return $response->withJson($json, 400); return $response->withJson($json, 400);

View file

@ -34,6 +34,34 @@ if (!function_exists('humanFileSize')) {
} }
} }
if (!function_exists('stringToBytes')) {
/**
* @param $str
* @return int|string
*/
function stringToBytes(string $str): int
{
$val = trim($str);
if (is_numeric($val)) {
return (int)$val;
}
$last = strtolower($val[strlen($val) - 1]);
$val = substr($val, 0, -1);
$val = (int)$val;
switch ($last) {
case 'g':
$val *= 1024;
case 'm':
$val *= 1024;
case 'k':
$val *= 1024;
}
return $val;
}
}
if (!function_exists('removeDirectory')) { if (!function_exists('removeDirectory')) {
/** /**
* Remove a directory and it's content * Remove a directory and it's content

View file

@ -1,6 +1,6 @@
{ {
"name": "sergix44/xbackbone", "name": "sergix44/xbackbone",
"version": "2.4", "version": "2.4.1",
"description": "A lightweight ShareX PHP backend", "description": "A lightweight ShareX PHP backend",
"type": "project", "type": "project",
"require": { "require": {

View file

@ -12,7 +12,7 @@
<div class="col-md-6 d-flex justify-content-center"> <div class="col-md-6 d-flex justify-content-center">
{% include 'comp/pager.twig' %} {% include 'comp/pager.twig' %}
</div> </div>
<div class="col-md-3 text-right"> <div class="col-md-3 text-lg-right text-center mb-3">
<div class="btn-group"> <div class="btn-group">
<div class="btn-group"> <div class="btn-group">
<button class="btn btn-outline-primary dropdown-toggle" type="button" id="dropdownOrder" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <button class="btn btn-outline-primary dropdown-toggle" type="button" id="dropdownOrder" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">