Sanitize image file names to remove special characters; fix existing image paths

This commit is contained in:
Edwin Noorlander 2025-11-11 18:10:26 +01:00
parent b1ce2ce3aa
commit e1cf2a3e46
4 changed files with 2 additions and 1 deletions

Binary file not shown.

View File

Before

Width:  |  Height:  |  Size: 281 KiB

After

Width:  |  Height:  |  Size: 281 KiB

View File

Before

Width:  |  Height:  |  Size: 218 KiB

After

Width:  |  Height:  |  Size: 218 KiB

View File

@ -159,7 +159,8 @@ class ItemController
if (!is_dir($uploadDir)) { if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0755, true); mkdir($uploadDir, 0755, true);
} }
$fileName = uniqid() . '_' . basename($file['name']); $safeName = preg_replace('/[^a-zA-Z0-9_\-\.]/', '_', basename($file['name']));
$fileName = uniqid() . '_' . $safeName;
$targetPath = $uploadDir . $fileName; $targetPath = $uploadDir . $fileName;
error_log("Attempting to move from " . $file['tmp_name'] . " to " . $targetPath); error_log("Attempting to move from " . $file['tmp_name'] . " to " . $targetPath);
if (move_uploaded_file($file['tmp_name'], $targetPath)) { if (move_uploaded_file($file['tmp_name'], $targetPath)) {