Refactor target directory path handling for profile picture uploads

This commit is contained in:
Fabian Schieder 2026-01-25 22:48:48 +01:00
parent ff3706478e
commit 81724c62b0

View File

@ -60,17 +60,13 @@ if (!$mime || !isset($allowedMimeToExt[$mime]))
$ext = $allowedMimeToExt[$mime]; $ext = $allowedMimeToExt[$mime];
// Ziel: Bilder in assets/images/profilePictures (relativ zum Projekt/Webroot) // Wichtig: Auf Linux ist ein Pfad mit führendem "/" ein Pfad ab Dateisystem-Root.
// WICHTIG: move_uploaded_file() braucht einen Dateisystempfad. DOCUMENT_ROOT ist je nach VHost/Alias nicht immer zuverlässig. // Für move_uploaded_file() brauchen wir einen Dateisystempfad; die Public-URL ist separat.
$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'] : ''; $documentRoot = isset($_SERVER['DOCUMENT_ROOT']) ? (string)$_SERVER['DOCUMENT_ROOT'] : '';
if ($documentRoot !== '') $webRoot = rtrim($documentRoot, "\\/");
{ $targetDir = $webRoot !== ''
// Nur zur Info: Das ist die vom Webserver gemeldete Webroot ? $webRoot . 'assets/images/profilePictures'
error_log('Upload: DOCUMENT_ROOT=' . $documentRoot . ' __DIR__=' . __DIR__ . ' targetDir=' . $targetDir); : __DIR__ . 'assets/images/profilePictures';
}
if (!is_dir($targetDir)) if (!is_dir($targetDir))
{ {