kohjhjhصثقصثقصثقgdfgdg
Ele57885fddfgdfgfghgقفغفغفقhfg555434536
/
home
/
u542670534
/
domains
/
inddigprintx1.com
/
public_html
/
Upload FileeE
HOME
<?php require_once 'db.php'; // Assuming this contains your DB connection as $conn if ($_SERVER['REQUEST_METHOD'] === 'POST') { $id = isset($_POST['id']) ? (int)$_POST['id'] : 0; $status = isset($_POST['status']) ? trim($_POST['status']) : null; $userRole = isset($_POST['user_role']) ? trim($_POST['user_role']) : ''; $newPath = ''; // Final path to be stored in DB // Handle file upload if (!empty($_FILES['new_image']['name']) && $_FILES['new_image']['error'] === UPLOAD_ERR_OK) { $file = $_FILES['new_image']; $ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); $allowed = ['jpg','jpeg','png','gif','webp']; if (in_array($ext, $allowed)) { $uploadDir = __DIR__ . '/uploads/'; if (!is_dir($uploadDir)) mkdir($uploadDir, 0755, true); $newName = time() . '_' . bin2hex(random_bytes(4)) . '.' . $ext; $fullPath = $uploadDir . $newName; if (move_uploaded_file($file['tmp_name'], $fullPath)) { $newPath = 'uploads/' . $newName; } } } // If no new image uploaded, fetch existing one to keep it if (empty($newPath)) { $stmt = $conn->prepare("SELECT image FROM card_image WHERE id = ?"); $stmt->bind_param("i", $id); $stmt->execute(); $stmt->bind_result($existingImage); if ($stmt->fetch()) { $newPath = $existingImage; } $stmt->close(); } // Build SQL query based on role and input if ($userRole === 'sales' && $status !== null) { $stmt = $conn->prepare("UPDATE card_image SET image = ?, status = ? WHERE id = ?"); $stmt->bind_param("ssi", $newPath, $status, $id); } else { $stmt = $conn->prepare("UPDATE card_image SET image = ? WHERE id = ?"); $stmt->bind_param("si", $newPath, $id); } $success = $stmt->execute(); $stmt->close(); echo json_encode([ 'status' => $success ? 'success' : 'error', 'message' => $success ? 'Updated successfully' : 'Failed to update record.' ]); exit; }