Refactor filename generation for user uploads to use a timestamp for uniqueness and filesystem safety
This commit is contained in:
parent
5499482637
commit
787c32fdf5
BIN
assets/images/profilePictures/user_10_69769485461a7618397775.jpg
Normal file
BIN
assets/images/profilePictures/user_10_69769485461a7618397775.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.6 KiB |
@ -106,10 +106,10 @@ if (!is_writable($targetDir))
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback-kompatibler Name (auch ohne random_bytes)
|
// Dateiname: user_<ID>_<Datum>.<ext>
|
||||||
$rand = uniqid('', true);
|
// Format ist dateisystem-sicher (keine Doppelpunkte) und eindeutig genug.
|
||||||
$rand = str_replace('.', '', $rand);
|
$timestamp = gmdate('Ymd-His');
|
||||||
$filename = 'user_' . $userId . '_' . $rand . '.' . $ext;
|
$filename = 'user_' . $userId . '_' . $timestamp . '.' . $ext;
|
||||||
$targetPath = rtrim($targetDir, "\\/") . DIRECTORY_SEPARATOR . $filename;
|
$targetPath = rtrim($targetDir, "\\/") . DIRECTORY_SEPARATOR . $filename;
|
||||||
|
|
||||||
if (!move_uploaded_file($tmp, $targetPath))
|
if (!move_uploaded_file($tmp, $targetPath))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user