Refactor file upload target directory handling and improve logging for diagnostics
This commit is contained in:
parent
dde5ac9d28
commit
ff3706478e
16
upload.php
16
upload.php
@ -60,13 +60,17 @@ if (!$mime || !isset($allowedMimeToExt[$mime]))
|
|||||||
|
|
||||||
$ext = $allowedMimeToExt[$mime];
|
$ext = $allowedMimeToExt[$mime];
|
||||||
|
|
||||||
// Wichtig: Auf Linux ist ein Pfad mit führendem "/" ein Pfad ab Dateisystem-Root.
|
// Ziel: Bilder in assets/images/profilePictures (relativ zum Projekt/Webroot)
|
||||||
// Für move_uploaded_file() brauchen wir einen Dateisystempfad; die Public-URL ist separat.
|
// 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)
|
||||||
$documentRoot = isset($_SERVER['DOCUMENT_ROOT']) ? (string)$_SERVER['DOCUMENT_ROOT'] : '';
|
$documentRoot = isset($_SERVER['DOCUMENT_ROOT']) ? (string)$_SERVER['DOCUMENT_ROOT'] : '';
|
||||||
$webRoot = rtrim($documentRoot, "\\/");
|
if ($documentRoot !== '')
|
||||||
$targetDir = $webRoot !== ''
|
{
|
||||||
? $webRoot . 'assets/images/profilePictures'
|
// Nur zur Info: Das ist die vom Webserver gemeldete Webroot
|
||||||
: __DIR__ . 'assets/images/profilePictures';
|
error_log('Upload: DOCUMENT_ROOT=' . $documentRoot . ' __DIR__=' . __DIR__ . ' targetDir=' . $targetDir);
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_dir($targetDir))
|
if (!is_dir($targetDir))
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user