Update: 2026-06-12 01:23:54
This commit is contained in:
@@ -4,15 +4,31 @@ require_once __DIR__ . '/../../functions.php';
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
uploadLog("🚀 [ride/card-image-driver/add.php] Card image upload started.");
|
||||
|
||||
try {
|
||||
$con = Database::get('main');
|
||||
} catch (Exception $e) {
|
||||
uploadLog("❌ DB Connection failed: " . $e->getMessage(), 'ERROR');
|
||||
http_response_code(500);
|
||||
echo json_encode(['status' => 'Database connection failed.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (isset($_FILES['image'])) {
|
||||
uploadLog("$_FILES['image'] metadata", 'INFO', [
|
||||
'name' => $_FILES['image']['name'] ?? 'unknown',
|
||||
'type' => $_FILES['image']['type'] ?? 'unknown',
|
||||
'size' => $_FILES['image']['size'] ?? 0,
|
||||
'upload_error_code' => $_FILES['image']['error'] ?? UPLOAD_ERR_OK
|
||||
]);
|
||||
} else {
|
||||
uploadLog("No 'image' file was sent in request.", 'WARNING');
|
||||
}
|
||||
|
||||
if (!isset($_FILES['image']) || $_FILES['image']['error'] != UPLOAD_ERR_OK) {
|
||||
$err = $_FILES['image']['error'] ?? 'missing_file';
|
||||
uploadLog("❌ File upload validation failed. Code: $err", 'ERROR');
|
||||
echo json_encode(['status' => 'The image file was not uploaded successfully.']);
|
||||
exit;
|
||||
}
|
||||
@@ -21,6 +37,7 @@ $image_file = $_FILES['image'];
|
||||
$driverID = filterRequest("driver_id");
|
||||
|
||||
if (empty($driverID)) {
|
||||
uploadLog("❌ Missing driver_id parameter.", 'ERROR');
|
||||
echo json_encode(['status' => 'Missing driver ID.']);
|
||||
exit;
|
||||
}
|
||||
@@ -58,7 +75,9 @@ if (!move_uploaded_file($image_file['tmp_name'], $target_file)) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$linlImage = 'https://ride.mobile-app.store/card_image/' . $new_filename;
|
||||
$host = $_SERVER['HTTP_HOST'] ?? 'ride.mobile-app.store';
|
||||
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http";
|
||||
$linlImage = "$protocol://$host/siro/card_image/" . $new_filename;
|
||||
|
||||
try {
|
||||
// استخدام Prepared Statements للحماية من الحقن (SQL Injection)
|
||||
@@ -73,6 +92,7 @@ try {
|
||||
':driver_id' => $driverID
|
||||
]);
|
||||
|
||||
uploadLog("✅ Card image updated successfully for driver_id: $driverID, URL: $linlImage");
|
||||
echo json_encode(['status' => 'Record updated successfully']);
|
||||
} else {
|
||||
$insertStmt = $con->prepare("INSERT INTO card_images (id, driver_id, image_name, link) VALUES (SHA2(UUID(), 256), :driver_id, :image_name, :link)");
|
||||
@@ -82,9 +102,11 @@ try {
|
||||
':link' => $linlImage
|
||||
]);
|
||||
|
||||
uploadLog("✅ Card image inserted successfully for driver_id: $driverID, URL: $linlImage");
|
||||
echo json_encode(['status' => 'Record inserted successfully']);
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
uploadLog("❌ Database error: " . $e->getMessage(), 'ERROR');
|
||||
error_log("Database Error in card-image-driver/add.php: " . $e->getMessage());
|
||||
echo json_encode(['status' => 'Database operation failed.']);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user