From 03af709a129776f876abbc3bbd8255038281fe20 Mon Sep 17 00:00:00 2001 From: Ray1111-aa Date: Wed, 28 Oct 2026 11:59:42 +0700 Subject: [PATCH] fix(backup): handle PostTooLargeException gracefully and add client-side file size guard --- .../Controllers/Admin/BackupController.php | 30 ++++++++++++++++++- bootstrap/app.php | 6 +++- resources/views/admin/backups/index.blade.php | 10 ++++++- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Admin/BackupController.php b/app/Http/Controllers/Admin/BackupController.php index 7f7df2c..1a4c173 100644 --- a/app/Http/Controllers/Admin/BackupController.php +++ b/app/Http/Controllers/Admin/BackupController.php @@ -60,7 +60,35 @@ class BackupController extends Controller $log->file_exists = File::exists($fullPath); }); - return view('admin.backups.index', compact('backupLogs', 'backups', 'stats', 'tableGroups')); + // Ambil info batas upload server PHP saat ini + $uploadMax = ini_get('upload_max_filesize') ?: '256M'; + $postMax = ini_get('post_max_size') ?: '256M'; + $maxUploadBytes = min($this->parseIniBytes($uploadMax), $this->parseIniBytes($postMax)); + $maxUploadHuman = $this->backupService->formatBytes($maxUploadBytes); + + return view('admin.backups.index', compact('backupLogs', 'backups', 'stats', 'tableGroups', 'maxUploadBytes', 'maxUploadHuman')); + } + + /** + * Konversi notasi string PHP INI (misal 256M, 1G) ke byte integer. + */ + protected function parseIniBytes(string $val): int + { + $val = trim($val); + $last = strtolower($val[strlen($val) - 1] ?? ''); + $num = (int) $val; + switch ($last) { + case 'g': + $num *= 1024 * 1024 * 1024; + break; + case 'm': + $num *= 1024 * 1024; + break; + case 'k': + $num *= 1024; + break; + } + return $num > 0 ? $num : 268435456; // Fallback 256 MB } /** diff --git a/bootstrap/app.php b/bootstrap/app.php index f9aafcb..72c436c 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -18,5 +18,9 @@ return Application::configure(basePath: dirname(__DIR__)) ]); }) ->withExceptions(function (Exceptions $exceptions): void { - // + $exceptions->render(function (\Illuminate\Http\Exceptions\PostTooLargeException $e, $request) { + $postMax = ini_get('post_max_size') ?: '256M'; + $uploadMax = ini_get('upload_max_filesize') ?: '256M'; + return back()->with('error', "Ukuran file yang Anda kirim terlalu besar dan melebihi batas konfigurasi server PHP (post_max_size: {$postMax}, upload_max_filesize: {$uploadMax}). Harap naikkan batas konfigurasi php.ini atau gunakan file yang lebih kecil."); + }); })->create(); diff --git a/resources/views/admin/backups/index.blade.php b/resources/views/admin/backups/index.blade.php index 8226d82..5719bdd 100644 --- a/resources/views/admin/backups/index.blade.php +++ b/resources/views/admin/backups/index.blade.php @@ -444,7 +444,7 @@

Tarik & Letakkan file .kmh di sini

atau klik untuk memilih dari komputer Anda

-

Format didukung: .kmh terenkripsi (Maks. 200 MB)

+

Format didukung: .kmh terenkripsi (Batas upload server: {{ $maxUploadHuman ?? '256 MB' }})