diff --git a/backend/auth/syria/uploadImage.php b/backend/auth/syria/uploadImage.php index 6fac716..d084d80 100644 --- a/backend/auth/syria/uploadImage.php +++ b/backend/auth/syria/uploadImage.php @@ -17,10 +17,6 @@ $driverID = filterRequest('driverID'); $imageType = filterRequest('imageType'); $country = filterRequest('country'); -if (empty($driverID)) { - jsonError('driverID is required.'); -} - if (empty($imageType)) { jsonError('imageType is required.'); } @@ -28,23 +24,31 @@ if (empty($imageType)) { // --------- تحديد الدولة --------- $country = strtolower(trim($country ?: '')); if (empty($country)) { - try { - $stmt = $con->prepare("SELECT country FROM drivers WHERE id = ?"); - $stmt->execute([$driverID]); - $country = strtolower(trim((string)$stmt->fetchColumn())); - } catch (Exception $e) { - $country = ''; + if (!empty($driverID)) { + try { + $stmt = $con->prepare("SELECT country FROM drivers WHERE id = ?"); + $stmt->execute([$driverID]); + $country = strtolower(trim((string)$stmt->fetchColumn())); + } catch (Exception $e) { + $country = ''; + } + } + if (empty($country)) { + $country = 'jordan'; } } if (!in_array($country, ['syria', 'jordan', 'egypt'])) { - $country = 'syria'; + $country = 'jordan'; } -uploadLog("📥 Params: driverID=$driverID, imageType=$imageType, country=$country"); +// --------- بادئة اسم الملف --------- +$prefix = !empty($driverID) ? $driverID : 'unregistered'; + +uploadLog("📥 Params: driverID=" . ($driverID ?: 'null') . ", imageType=$imageType, country=$country"); // --------- رفع الملف --------- $targetDir = __DIR__ . "/../../auth/uploads/{$country}/"; -$result = uploadImageSecure('image', $targetDir, $driverID . '_' . $imageType); +$result = uploadImageSecure('image', $targetDir, $prefix . '_' . $imageType); if (!$result['success']) { uploadLog("❌ Upload failed: {$result['error']}", 'ERROR', [ @@ -63,7 +67,7 @@ $basePath = rtrim(dirname(dirname(dirname($_SERVER['SCRIPT_NAME']))), '/'); $url = "$protocol://$host{$basePath}/auth/uploads/{$country}/{$result['filename']}"; uploadLog("✅ Uploaded: {$result['path']} -> $url", 'INFO', [ - 'driverID' => $driverID, + 'driverID' => ($driverID ?: 'null'), 'imageType' => $imageType, 'country' => $country, ]); @@ -72,7 +76,7 @@ jsonSuccess([ 'url' => $url, 'file_link' => $url, 'filename' => $result['filename'], - 'driverID' => $driverID, + 'driverID' => ($driverID ?: ''), 'imageType' => $imageType, 'country' => $country, ]);