From ff3706478e3eddbd4622b0ab9a632fe4d986c553 Mon Sep 17 00:00:00 2001 From: Fabian Schieder Date: Sun, 25 Jan 2026 22:48:00 +0100 Subject: [PATCH] Refactor file upload target directory handling and improve logging for diagnostics --- upload.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/upload.php b/upload.php index b4ba069..03e7249 100644 --- a/upload.php +++ b/upload.php @@ -60,13 +60,17 @@ if (!$mime || !isset($allowedMimeToExt[$mime])) $ext = $allowedMimeToExt[$mime]; -// Wichtig: Auf Linux ist ein Pfad mit führendem "/" ein Pfad ab Dateisystem-Root. -// Für move_uploaded_file() brauchen wir einen Dateisystempfad; die Public-URL ist separat. +// Ziel: Bilder in assets/images/profilePictures (relativ zum Projekt/Webroot) +// WICHTIG: move_uploaded_file() braucht einen Dateisystempfad. DOCUMENT_ROOT ist je nach VHost/Alias nicht immer zuverlässig. +$targetDir = __DIR__ . '/assets/images/profilePictures'; + +// Optionales Logging zur Diagnose auf der VPS (landet im PHP/Apache Error-Log) $documentRoot = isset($_SERVER['DOCUMENT_ROOT']) ? (string)$_SERVER['DOCUMENT_ROOT'] : ''; -$webRoot = rtrim($documentRoot, "\\/"); -$targetDir = $webRoot !== '' - ? $webRoot . 'assets/images/profilePictures' - : __DIR__ . 'assets/images/profilePictures'; +if ($documentRoot !== '') +{ + // Nur zur Info: Das ist die vom Webserver gemeldete Webroot + error_log('Upload: DOCUMENT_ROOT=' . $documentRoot . ' __DIR__=' . __DIR__ . ' targetDir=' . $targetDir); +} if (!is_dir($targetDir)) {