<?php
include 'connect.php';
$SliderImageName = $_FILES['sliderImage']['name'];
$SliderImageTmp = $_FILES['sliderImage']['tmp_name'];
$SliderImageExtension = pathinfo($SliderImageName, PATHINFO_EXTENSION); // Get the file extension

$folderName = "../images/Slider/";
$newItemImageName = uniqid() . '.' . $SliderImageExtension;
$destination = $folderName . $newItemImageName;
$SliderImage = "images/Slider/" . $newItemImageName;


if (move_uploaded_file($SliderImageTmp, $destination)) {
    $sql = "INSERT INTO a_slider (SliderImage) VALUES ('$SliderImage')";
    $result = mysqli_query($con,$sql);
    if ($result) {
        echo json_encode(array('message' => 'Item added successfully.'));
    } else {
        echo json_encode(array('error' => mysqli_error($con)));
    }
} else {
    echo json_encode(array('error' => 'Error uploading the file.'));
}
?>
