Refactor target directory path handling for profile picture uploads to ensure correct leading slash

This commit is contained in:
Fabian Schieder 2026-01-25 23:00:54 +01:00
parent 391f9332e2
commit 2338e22447

View File

@ -64,9 +64,13 @@ $ext = $allowedMimeToExt[$mime];
// Für move_uploaded_file() brauchen wir einen Dateisystempfad; die Public-URL ist separat. // Für move_uploaded_file() brauchen wir einen Dateisystempfad; die Public-URL ist separat.
$documentRoot = isset($_SERVER['DOCUMENT_ROOT']) ? (string)$_SERVER['DOCUMENT_ROOT'] : ''; $documentRoot = isset($_SERVER['DOCUMENT_ROOT']) ? (string)$_SERVER['DOCUMENT_ROOT'] : '';
$webRoot = rtrim($documentRoot, "\\/"); $webRoot = rtrim($documentRoot, "\\/");
// Wichtig: relativer Zielpfad MUSS mit '/' beginnen, sonst entsteht z.B. "Websiteassets/...".
$relativeTargetDir = '/assets/images/profilePictures';
$targetDir = $webRoot !== '' $targetDir = $webRoot !== ''
? $webRoot . 'assets/images/profilePictures' ? $webRoot . $relativeTargetDir
: __DIR__ . 'assets/images/profilePictures'; : rtrim(__DIR__, "\\/") . $relativeTargetDir;
if (!is_dir($targetDir)) if (!is_dir($targetDir))
{ {