Refactor profile picture upload path handling to ensure correct directory structure and improve logging
This commit is contained in:
parent
81724c62b0
commit
f98881ce97
14
upload.php
14
upload.php
@ -64,9 +64,18 @@ $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: 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 !== ''
|
$targetDir = $webRoot !== ''
|
||||||
? $webRoot . 'assets/images/profilePictures'
|
? $webRoot . $relativeTargetDir
|
||||||
: __DIR__ . 'assets/images/profilePictures';
|
: rtrim(__DIR__, "\\/") . $relativeTargetDir;
|
||||||
|
|
||||||
|
error_log('Upload: resolved targetDir=' . $targetDir);
|
||||||
|
|
||||||
if (!is_dir($targetDir))
|
if (!is_dir($targetDir))
|
||||||
{
|
{
|
||||||
@ -91,6 +100,7 @@ $rand = uniqid('', true);
|
|||||||
$rand = str_replace('.', '', $rand);
|
$rand = str_replace('.', '', $rand);
|
||||||
$filename = 'user_' . $userId . '_' . $rand . '.' . $ext;
|
$filename = 'user_' . $userId . '_' . $rand . '.' . $ext;
|
||||||
$targetPath = rtrim($targetDir, "\\/") . DIRECTORY_SEPARATOR . $filename;
|
$targetPath = rtrim($targetDir, "\\/") . DIRECTORY_SEPARATOR . $filename;
|
||||||
|
error_log('Upload: resolved targetPath=' . $targetPath);
|
||||||
|
|
||||||
if (!move_uploaded_file($tmp, $targetPath))
|
if (!move_uploaded_file($tmp, $targetPath))
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user