Skip to content

Commit

Permalink
Fixed inaccurate message in case of file too large (fixes #15)
Browse files Browse the repository at this point in the history
Minor fix to the mobile layout
  • Loading branch information
sergix44 committed Jan 24, 2019
1 parent f49d6ef commit dbc55bd
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v2.4.1
+ Fixed error message when the file is too large. (#15)
+ Fixed button alignment.

## v2.4
+ Added function to remove orphaned files.
+ Switch between tab and gallery mode using an admin account.
Expand Down
10 changes: 10 additions & 0 deletions app/Controllers/UploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ public function upload(Request $request, Response $response): Response

$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) {
$json['message'] = 'Token not specified.';
return $response->withJson($json, 400);
Expand Down
28 changes: 28 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,34 @@ function humanFileSize($size, $precision = 2): string
}
}

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')) {
/**
* Remove a directory and it's content
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sergix44/xbackbone",
"version": "2.4",
"version": "2.4.1",
"description": "A lightweight ShareX PHP backend",
"type": "project",
"require": {
Expand Down
2 changes: 1 addition & 1 deletion resources/templates/dashboard/pager_header.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div class="col-md-6 d-flex justify-content-center">
{% include 'comp/pager.twig' %}
</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">
<button class="btn btn-outline-primary dropdown-toggle" type="button" id="dropdownOrder" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Expand Down

0 comments on commit dbc55bd

Please sign in to comment.