Refactor filename generation for user uploads to use a timestamp for uniqueness and filesystem safety

This commit is contained in:
Fabian Schieder 2026-01-25 23:19:39 +01:00
parent 5499482637
commit 787c32fdf5
2 changed files with 4 additions and 4 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

@ -106,10 +106,10 @@ if (!is_writable($targetDir))
exit();
}
// Fallback-kompatibler Name (auch ohne random_bytes)
$rand = uniqid('', true);
$rand = str_replace('.', '', $rand);
$filename = 'user_' . $userId . '_' . $rand . '.' . $ext;
// Dateiname: user_<ID>_<Datum>.<ext>
// Format ist dateisystem-sicher (keine Doppelpunkte) und eindeutig genug.
$timestamp = gmdate('Ymd-His');
$filename = 'user_' . $userId . '_' . $timestamp . '.' . $ext;
$targetPath = rtrim($targetDir, "\\/") . DIRECTORY_SEPARATOR . $filename;
if (!move_uploaded_file($tmp, $targetPath))