diff --git a/upload.php b/upload.php index 03e7249..b4ba069 100644 --- a/upload.php +++ b/upload.php @@ -60,17 +60,13 @@ if (!$mime || !isset($allowedMimeToExt[$mime])) $ext = $allowedMimeToExt[$mime]; -// 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) +// 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. $documentRoot = isset($_SERVER['DOCUMENT_ROOT']) ? (string)$_SERVER['DOCUMENT_ROOT'] : ''; -if ($documentRoot !== '') -{ - // Nur zur Info: Das ist die vom Webserver gemeldete Webroot - error_log('Upload: DOCUMENT_ROOT=' . $documentRoot . ' __DIR__=' . __DIR__ . ' targetDir=' . $targetDir); -} +$webRoot = rtrim($documentRoot, "\\/"); +$targetDir = $webRoot !== '' + ? $webRoot . 'assets/images/profilePictures' + : __DIR__ . 'assets/images/profilePictures'; if (!is_dir($targetDir)) {