remove random suffix from uploaded filenames: now {driverID}_{imageType}.{ext}

This commit is contained in:
Hamza-Ayed
2026-06-25 04:21:58 +03:00
parent f5a5ffc10c
commit 0b9e5dfa03

View File

@@ -59,6 +59,20 @@ if (!$result['success']) {
jsonError($result['error']); jsonError($result['error']);
} }
// --------- إزالة العشوائية من اسم الملف ---------
// الاسم يكون فقط: {driverID}_{imageType}.jpg (بدون random hex)
$ext = pathinfo($result['filename'], PATHINFO_EXTENSION);
$simpleName = $prefix . '_' . $imageType . '.' . $ext;
$simplePath = rtrim($targetDir, '/') . '/' . $simpleName;
if (file_exists($simplePath)) {
unlink($simplePath); // overwrite
}
rename($result['path'], $simplePath);
$result['filename'] = $simpleName;
$result['path'] = $simplePath;
// --------- بناء الرابط العام --------- // --------- بناء الرابط العام ---------
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http'; $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
$host = getenv('APP_DOMAIN') ?: ($_SERVER['HTTP_HOST'] ?? 'api.siromove.com'); $host = getenv('APP_DOMAIN') ?: ($_SERVER['HTTP_HOST'] ?? 'api.siromove.com');