Update: 2026-06-12 01:23:54
This commit is contained in:
@@ -6,17 +6,30 @@
|
||||
|
||||
require_once __DIR__ . '/connect.php'; // يفترض أنه يستدعي core/bootstrap.php
|
||||
|
||||
appLog("🚀 [upload_profile_image.php] بدأ تنفيذ سكربت رفع الصورة");
|
||||
uploadLog("🚀 [uploadImagePortrate.php] Profile image upload script execution started.");
|
||||
|
||||
try {
|
||||
// Check if $_FILES has errors
|
||||
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 the request.", 'WARNING');
|
||||
}
|
||||
|
||||
// 1. Rate Limiting للرفع
|
||||
$limiter = new RateLimiter($redis);
|
||||
$limiter->enforce(RateLimiter::identifier($user_id ?? null), 'upload');
|
||||
|
||||
$driverID = filterRequest("driverID");
|
||||
appLog("📥 Received driverID: $driverID");
|
||||
uploadLog("📥 Received driverID: $driverID");
|
||||
|
||||
if (empty($driverID)) {
|
||||
uploadLog("❌ Driver ID is missing.", 'ERROR');
|
||||
jsonError('Driver ID is required.', 400);
|
||||
}
|
||||
|
||||
@@ -25,16 +38,18 @@ try {
|
||||
$uploadResult = uploadImageSecure('image', $target_dir, $driverID);
|
||||
|
||||
if (!$uploadResult['success']) {
|
||||
uploadLog("❌ Image upload failed", 'ERROR', ['driverID' => $driverID, 'error' => $uploadResult['error']]);
|
||||
securityLog("❌ Image upload failed", ['driverID' => $driverID, 'error' => $uploadResult['error']]);
|
||||
jsonError($uploadResult['error'], 400);
|
||||
}
|
||||
|
||||
$new_filename = $uploadResult['filename'];
|
||||
appLog("✅ File moved successfully to: " . $uploadResult['path']);
|
||||
uploadLog("✅ File moved successfully to: " . $uploadResult['path']);
|
||||
|
||||
// 3. تحديث قاعدة البيانات
|
||||
$linkImage = 'https://api.intaleq.xyz/siro_v3/portrate_captain_image/' . $new_filename;
|
||||
$uploadDate = date("Y-m-d H:i:s");
|
||||
// 3. تحديث قاعدة البيانات ديناميكياً
|
||||
$host = $_SERVER['HTTP_HOST'] ?? 'api.siromove.com';
|
||||
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http";
|
||||
$linkImage = "$protocol://$host/siro/portrate_captain_image/" . $new_filename;
|
||||
|
||||
// تأكد من أن الاتصال قادم من connect.php أو اجلبه
|
||||
$con = Database::get('main');
|
||||
@@ -48,7 +63,6 @@ try {
|
||||
// تحديث
|
||||
$updateSQL = "UPDATE imageProfileCaptain SET image_name = ?, link = ? WHERE driverID = ?";
|
||||
$updateStmt = $con->prepare($updateSQL);
|
||||
// Note: imageProfileCaptain doesn't seem to have 'upload_date' in the original insert, but let's check if we should add it. Let's just update image_name and link as in the insert statement.
|
||||
$success = $updateStmt->execute([$new_filename, $linkImage, $driverID]);
|
||||
} else {
|
||||
// إدخال جديد
|
||||
@@ -58,10 +72,10 @@ try {
|
||||
}
|
||||
|
||||
if ($success) {
|
||||
appLog("✅ Record updated for driverID: $driverID");
|
||||
uploadLog("✅ Record updated for driverID: $driverID, Link: $linkImage");
|
||||
jsonSuccess(['file_link' => $linkImage], 'Record updated successfully.');
|
||||
} else {
|
||||
appLog("❌ Failed to update DB record for driverID: $driverID");
|
||||
uploadLog("❌ Failed to update DB record for driverID: $driverID", 'ERROR');
|
||||
jsonError('Failed to update record.', 500);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user