:: **Zploit** v1.0 | Current Path: **/home/kreativepixelz/www/sukhadaworldapp/admin/**
:: Editing File: slider_save.php
<?php include_once("session.php"); include("db.php"); $upload_dir = '../uploads/slider/'; // Create folder if not exists if (!is_dir($upload_dir)) { mkdir($upload_dir, 0777, true); } if ($_SERVER["REQUEST_METHOD"] == "POST") { $status = trim($_POST['status'] ?? 'Inactive'); $image_path = NULL; // Validate image if (empty($_FILES['image']['name'])) { $_SESSION['error'] = "Please upload an image."; header("Location: slider_add.php"); exit; } if ($_FILES['image']['error'] === UPLOAD_ERR_OK) { $file_ext = strtolower(pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION)); $allowed_ext = ['jpg', 'jpeg', 'png', 'gif', 'webp']; if (!in_array($file_ext, $allowed_ext)) { $_SESSION['error'] = "Invalid image type! Only JPG, PNG, GIF, WEBP allowed."; header("Location: slider_add.php"); exit; } // Create random unique filename $new_file_name = uniqid('slider_') . '.' . $file_ext; $destination = $upload_dir . $new_file_name; // Upload the file if (move_uploaded_file($_FILES['image']['tmp_name'], $destination)) { $image_path = $new_file_name; } else { $_SESSION['error'] = "Image upload failed. Check folder permissions."; header("Location: slider_add.php"); exit; } } // Insert into database $sql = "INSERT INTO slider (image, status) VALUES (?, ?)"; $stmt = mysqli_prepare($conn, $sql); mysqli_stmt_bind_param($stmt, "ss", $image_path, $status); if (mysqli_stmt_execute($stmt)) { $_SESSION['success'] = "Slider image added successfully!"; header("Location: slider.php"); exit; } else { $_SESSION['error'] = "Database error: " . mysqli_error($conn); // Delete uploaded file if DB insert failed if ($image_path && file_exists($upload_dir . $image_path)) { unlink($upload_dir . $image_path); } header("Location: slider_add.php"); exit; } mysqli_stmt_close($stmt); mysqli_close($conn); } else { $_SESSION['error'] = "Invalid Request Method."; header("Location: slider_add.php"); exit; } ?>