Update: 2026-06-12 01:23:54

This commit is contained in:
Hamza-Ayed
2026-06-12 01:23:54 +03:00
parent 7049c7468c
commit ef6b52d2e3
47 changed files with 1480 additions and 1472 deletions

View File

@@ -1,31 +1,48 @@
<?php
require_once __DIR__ . '/../connect.php';
// Get the image file from the request.
$image_file = $_FILES['image'];
header('Content-Type: application/json');
uploadLog("🚀 [EgyptDocuments/uploadEgyptIdBack.php] Egyptian ID back upload started.");
$driverID = filterRequest("driverID");
// Define allowed extensions
$allowed_extensions = ['jpg', 'jpeg', 'png'];
// Get the image file from the request.
$image_file = $_FILES['image'];
// Check if the image file was uploaded successfully.
if ($image_file['error'] !== UPLOAD_ERR_OK) {
echo "Image upload failed";
exit;
if (empty($driverID)) {
uploadLog("❌ Missing driverID parameter.", 'ERROR');
jsonError("driverID is required.");
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 the 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');
jsonError("Image upload failed");
exit;
}
$image_file = $_FILES['image'];
$allowed_extensions = ['jpg', 'jpeg', 'png'];
// Get file information
$image_name = $image_file['name'];
$image_size = $image_file['size'];
$image_extension = strtolower(pathinfo($image_name, PATHINFO_EXTENSION));
// Validate file extension
if (!in_array($image_extension, $allowed_extensions)) {
echo "Invalid image format";
exit;
if (!in_array($image_extension, $allowed_extensions, true)) {
uploadLog("Invalid image format extension: .$image_extension", 'ERROR');
jsonError("Invalid image format");
exit;
}
// Validate MIME type
@@ -34,38 +51,42 @@ $mime_type = finfo_file($finfo, $image_file['tmp_name']);
finfo_close($finfo);
$allowed_mime_types = ['image/jpeg', 'image/png', 'image/jpg'];
if (!in_array($mime_type, $allowed_mime_types)) {
echo "Invalid image format (MIME mismatch)";
exit;
if (!in_array($mime_type, $allowed_mime_types, true)) {
uploadLog("Invalid MIME type: $mime_type", 'ERROR');
jsonError("Invalid image format (MIME mismatch)");
exit;
}
// Generate a unique filename using timestamp and random string
// Generate a unique filename using driverID
$new_filename = $driverID . '.' . $image_extension;
// Set target directory for uploads
$target_dir = "card_image/";
$target_dir = __DIR__ . "/card_image/";
if (!is_dir($target_dir)) {
mkdir($target_dir, 0755, true);
}
// Construct target file path
$target_file = $target_dir . $new_filename;
// Move the image file to the target location
if (!move_uploaded_file($image_file['tmp_name'], $target_file)) {
echo json_encode(array('status' => "Failed to save image")); ;
exit;
uploadLog("Failed to save image to target file: $target_file", 'ERROR');
jsonError("Failed to save image");
exit;
}
// Store additional information (modify based on your needs)
$image_url = $target_dir . $new_filename; // Update if needed
$image_details = [
"name" => $image_name,
"size" => $image_size,
"extension" => $image_extension,
"url" => $image_url,
];
// Resolve dynamic URL
$host = $_SERVER['HTTP_HOST'] ?? 'api.siromove.com';
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http";
$image_url = "$protocol://$host/siro/EgyptDocuments/card_image/" . $new_filename;
// Use the image details for further processing (e.g., display, store in database)
// ...
echo json_encode(array('status' => 'Image uploaded successfully!'));
uploadLog("✅ Egypt ID back uploaded successfully. URL: $image_url");
printSuccess([
"status" => "success",
"url" => $image_url,
"file_link" => $image_url,
"image_url" => $image_url
]);
?>