Update: 2026-06-25 03:28:59
This commit is contained in:
75
backend/auth/syria/uploadImage.php
Normal file
75
backend/auth/syria/uploadImage.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
// ============================================================
|
||||
// auth/syria/uploadImage.php
|
||||
// رفع صور وثائق السائق (هوية، رخصة، صورة شخصية، ...)
|
||||
// يخزّنها في مجلدات حسب الدولة: auth/uploads/{country}/
|
||||
// ============================================================
|
||||
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
uploadLog("🚀 [uploadImage.php] Document upload started.");
|
||||
|
||||
// --------- قراءة الحقول ---------
|
||||
$driverID = filterRequest('driverID');
|
||||
$imageType = filterRequest('imageType');
|
||||
$country = filterRequest('country');
|
||||
|
||||
if (empty($driverID)) {
|
||||
jsonError('driverID is required.');
|
||||
}
|
||||
|
||||
if (empty($imageType)) {
|
||||
jsonError('imageType is required.');
|
||||
}
|
||||
|
||||
// --------- تحديد الدولة ---------
|
||||
$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 (!in_array($country, ['syria', 'jordan', 'egypt'])) {
|
||||
$country = 'syria';
|
||||
}
|
||||
|
||||
uploadLog("📥 Params: driverID=$driverID, imageType=$imageType, country=$country");
|
||||
|
||||
// --------- رفع الملف ---------
|
||||
$targetDir = __DIR__ . "/../../auth/uploads/{$country}/";
|
||||
$result = uploadImageSecure('image', $targetDir, $driverID . '_' . $imageType);
|
||||
|
||||
if (!$result['success']) {
|
||||
uploadLog("❌ Upload failed: {$result['error']}", 'ERROR', [
|
||||
'driverID' => $driverID,
|
||||
'imageType' => $imageType,
|
||||
'country' => $country,
|
||||
]);
|
||||
jsonError($result['error']);
|
||||
}
|
||||
|
||||
// --------- بناء الرابط العام ---------
|
||||
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
|
||||
$host = getenv('APP_DOMAIN') ?: ($_SERVER['HTTP_HOST'] ?? 'api.siromove.com');
|
||||
|
||||
$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,
|
||||
'imageType' => $imageType,
|
||||
'country' => $country,
|
||||
]);
|
||||
|
||||
jsonSuccess([
|
||||
'url' => $url,
|
||||
'file_link' => $url,
|
||||
'filename' => $result['filename'],
|
||||
'driverID' => $driverID,
|
||||
'imageType' => $imageType,
|
||||
'country' => $country,
|
||||
]);
|
||||
Reference in New Issue
Block a user