diff --git a/upload.php b/upload.php index b4ba069..9875ec6 100644 --- a/upload.php +++ b/upload.php @@ -64,9 +64,18 @@ $ext = $allowedMimeToExt[$mime]; // Für move_uploaded_file() brauchen wir einen Dateisystempfad; die Public-URL ist separat. $documentRoot = isset($_SERVER['DOCUMENT_ROOT']) ? (string)$_SERVER['DOCUMENT_ROOT'] : ''; $webRoot = rtrim($documentRoot, "\\/"); + +// Wichtig: Beim Zusammenbauen muss ein '/' zwischen Webroot und relativem Pfad stehen. +// Sonst wird z.B. "/FSST/Website" + "assets/..." zu "/FSST/Websiteassets/...". +$relativeTargetDir = '/assets/images/profilePictures'; + +// Primär: Wenn DOCUMENT_ROOT sauber gesetzt ist, nutze es. +// Fallback: nutze __DIR__ (wenn upload.php im Webroot liegt). $targetDir = $webRoot !== '' - ? $webRoot . 'assets/images/profilePictures' - : __DIR__ . 'assets/images/profilePictures'; + ? $webRoot . $relativeTargetDir + : rtrim(__DIR__, "\\/") . $relativeTargetDir; + +error_log('Upload: resolved targetDir=' . $targetDir); if (!is_dir($targetDir)) { @@ -91,6 +100,7 @@ $rand = uniqid('', true); $rand = str_replace('.', '', $rand); $filename = 'user_' . $userId . '_' . $rand . '.' . $ext; $targetPath = rtrim($targetDir, "\\/") . DIRECTORY_SEPARATOR . $filename; +error_log('Upload: resolved targetPath=' . $targetPath); if (!move_uploaded_file($tmp, $targetPath)) {