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];
// 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))
{