51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Middleware;
|
||
|
|
||
|
use App\Helpers\MiscHelper;
|
||
|
use Closure;
|
||
|
use Illuminate\Http\Request;
|
||
|
|
||
|
class CheckMaxPostSizeExceeded
|
||
|
{
|
||
|
protected $exclude = [
|
||
|
'/admin/photos/analyse/*',
|
||
|
'/admin/photos/regenerate-thumbnails/*'
|
||
|
];
|
||
|
|
||
|
public function handle(Request $request, Closure $next)
|
||
|
{
|
||
|
if ($request->method() == 'POST' && !$this->shouldExclude($request))
|
||
|
{
|
||
|
// Check post limit and see if it may have been exceeded
|
||
|
$postLimit = MiscHelper::convertToBytes(ini_get('post_max_size'));
|
||
|
|
||
|
if (
|
||
|
(isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH'] > $postLimit) ||
|
||
|
(empty($_POST) && empty($_REQUEST))
|
||
|
)
|
||
|
{
|
||
|
$request->session()->flash('error', trans('global.post_max_exceeded'));
|
||
|
return back();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return $next($request);
|
||
|
}
|
||
|
|
||
|
protected function shouldExclude(Request $request)
|
||
|
{
|
||
|
foreach ($this->exclude as $exclude)
|
||
|
{
|
||
|
if ($exclude !== '/') {
|
||
|
$exclude = trim($exclude, '/');
|
||
|
}
|
||
|
|
||
|
if ($request->is($exclude)) {
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
}
|