Domain: amberpublishers.in
Server Adress: 86.38.243.169
privdayz.com
<?php
session_start();
require 'include/PHPHelper.php';
if (!isset($_SESSION['userID'])) {
header("location: login.php");
}
else {
if (isset($_POST['submit'])) {
$sectorName = mysqli_real_escape_string($conn, trim($_POST['sectorName']));
$sectorDescription = mysqli_real_escape_string($conn, trim($_POST['sectorDescription']));
$sectorIcon = mysqli_real_escape_string($conn, trim($_POST['sectorIcon']));
$sectorImage = $_FILES['sectorImage']['name'];
$sectorImage_tmp = $_FILES['sectorImage']['tmp_name'];
$sectorImage_size = $_FILES['sectorImage']['size'];
$sectorImage_type = $_FILES['sectorImage']['type'];
$sectorImage_ext = strtolower(pathinfo($sectorImage, PATHINFO_EXTENSION));
$sectorImage_new_name = $sectorName . '.webp'; // Set the extension to WebP
$sectorImage_store = "../assets/img/sectors/" . $sectorImage_new_name;
$sectorImage_error = $_FILES['sectorImage']['error'];
$sectorImage_max_size = 2097152;
$sectorImage_allowed_ext = array('png', 'jpeg', 'jpg', 'webp'); // Allowed image extensions
if (empty($sectorName) || empty($sectorDescription) || empty($sectorIcon) || empty($sectorImage)) {
echo "<script>alert('Please fill all the fields.')</script>";
} else {
if ($sectorImage_error === 0) {
if ($sectorImage_size <= $sectorImage_max_size) {
if (in_array($sectorImage_ext, $sectorImage_allowed_ext)) {
// Convert the image to WebP format
$image = imagecreatefromstring(file_get_contents($sectorImage_tmp));
if (imagewebp($image, $sectorImage_store)) {
// Successfully converted and saved as WebP
imagedestroy($image);
$sql = "INSERT INTO `sectors` (`id`, `sectorName`, `sectorDescription`, `icon`, `image`) VALUES ('', '$sectorName', '$sectorDescription', '$sectorIcon', '$sectorImage_new_name');";
$result = mysqli_query($conn, $sql);
if ($result) {
echo "<script>alert('Sector Added Successfully.')</script>";
echo "<script>window.location.href='sectors.php'</script>";
} else {
echo "<script>alert('Something went wrong.')</script>";
}
} else {
echo "<script>alert('Image conversion to WebP failed.')</script>";
}
} else {
echo "<script>alert('Please upload a valid image.')</script>";
}
} else {
echo "<script>alert('Please upload an image less than 2MB.')</script>";
}
} else {
echo "<script>alert('Something went wrong.')</script>";
echo "<script>window.location.href='addsector.php'</script>";
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<?php
$title = "Add New Sector || Master Clean India";
include 'include/head.php';
?>
<body>
<!-- ======= Header ======= -->
<?php
include 'include/header.php';
?>
<!-- End Header -->
<!-- ======= Sidebar ======= -->
<?php
include 'include/sidebar.php';
?>
<!-- End Sidebar-->
<main id="main" class="main">
<div class="pagetitle">
<h1>Add New Sector</h1>
<nav>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="index.php">Dashboard</a></li>
<li class="breadcrumb-item"><a href="sectors.php">Sectors</a></li>
<li class="breadcrumb-item active">Add New Sector</li>
</ol>
</nav>
</div><!-- End Page Title -->
<section class="section">
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<div class="card-title">
<h5>Add New Sector</h5>
<div class="form">
<form method="POST" class="addServiceForm" id="addServiceForm" enctype="multipart/form-data">
<div class="row mb-3">
<label for="sectorName" class="col-md-4 col-lg-3 col-form-label">Sector Name</label>
<div class="col-md-8 col-lg-9">
<input name="sectorName" type="text" class="form-control" id="sectorName" placeholder="Add Sector Name">
</div>
</div>
<div class="row mb-3">
<label for="sectorDescription" class="col-md-4 col-lg-3 col-form-label">Sector Description</label>
<div class="col-md-8 col-lg-9">
<textarea name="sectorDescription" class="form-control" id="sectorDescription" rows="8" placeholder="Add Sector Description"></textarea>
</div>
</div>
<div class="row mb-3">
<label for="sectorIcon" class="col-md-4 col-lg-3 col-form-label">Sector Icon</label>
<div class="col-md-8 col-lg-9">
<input name="sectorIcon" type="text" class="form-control" id="sectorIcon" placeholder="Add Sector Icon">
</div>
</div>
<div class="row mb-3">
<label for="sectorImage" class="col-md-4 col-lg-3 col-form-label">Sector Image</label>
<div class="col-md-8 col-lg-9">
<input type="file" name="sectorImage" id="sectorImage" class="form-control" accept="image/png, image/jpeg, image/webp" required>
</div>
</div>
<div class="row mt-3">
<div class="text-center">
<button type="submit" name="submit" id="submit" class="btn btn-primary col-lg-12">Add Sector</button>
<span id="msg"></span>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</main><!-- End #main -->
<!-- ======= Footer ======= -->
<?php
include 'include/footer.php';
?>
</body>
</html>
