From d31e5afa57f4297e77cca9c8af6ecc383d969595 Mon Sep 17 00:00:00 2001 From: fds2610-bot Date: Fri, 15 May 2026 17:53:12 +0200 Subject: [PATCH] Fix: Beleg-Upload in Bank-Zuordnung speichert Datei jetzt im korrekten public/static/uploads-Pfad --- src/Controllers/BankController.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Controllers/BankController.php b/src/Controllers/BankController.php index d79b848..47a9f11 100644 --- a/src/Controllers/BankController.php +++ b/src/Controllers/BankController.php @@ -246,20 +246,22 @@ class BankController View::redirect("/bank/$id", 'Nicht erlaubtes Dateiformat.', 'error'); } - $ext = $allowedMime[$mime]; - $hash = hash_file('sha256', $file['tmp_name']); - $filename = $hash . '.' . $ext; - $dir = BASE_DIR . '/storage/belege/'; - if (!is_dir($dir)) mkdir($dir, 0755, true); - $dest = $dir . $filename; - if (!file_exists($dest)) { - move_uploaded_file($file['tmp_name'], $dest); - } + $ext = $allowedMime[$mime]; + $belegNr = Beleg::generateBelegNr(); + $year = date('Y', strtotime($transaction['wertstellung'])); + $relDir = "static/uploads/{$year}/{$belegNr}"; + $absDir = dirname(__DIR__, 2) . "/public/{$relDir}"; + if (!is_dir($absDir)) mkdir($absDir, 0755, true); + + $storagePath = "{$relDir}/original.{$ext}"; + $absPath = dirname(__DIR__, 2) . "/public/{$storagePath}"; + move_uploaded_file($file['tmp_name'], $absPath); + $hash = hash_file('sha256', $absPath); $belegId = Beleg::create([ - 'beleg_nr' => Beleg::generateBelegNr(), + 'beleg_nr' => $belegNr, 'filename' => $file['name'], - 'storage_path' => 'storage/belege/' . $filename, + 'storage_path' => $storagePath, 'mime_type' => $mime, 'file_hash' => $hash, 'beleg_datum' => $transaction['wertstellung'],