|
Server IP : 2a02:4780:11:1596:0:cbc:26e7:10 / Your IP : 216.73.217.7 Web Server : LiteSpeed System : Linux in-mum-web1496.main-hosting.eu 5.14.0-611.38.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Mar 10 17:21:28 EDT 2026 x86_64 User : u213657319 ( 213657319) PHP Version : 8.3.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : OFF | Python : OFF Directory (0755) : /home/u213657319/domains/mutiyanglobal.com/public_html/admin/ |
| [ Home ] | [ C0mmand ] | [ Upload File ] |
|---|
<?php
session_start();
include 'check.php';
if(empty($_SESSION['emailId'])){
header("Location: index.php");
exit();
}
include '../connection.php';
include 'constant_file.php';
$display_message = '';
if(isset($_POST['submit'])) {
// Sabhi fields ko sanitize karna taaki single quote (') se error na aaye
$ct_id = mysqli_real_escape_string($con, $_POST['ct_id']);
$cid = mysqli_real_escape_string($con, $_POST['cid']);
$p_name = mysqli_real_escape_string($con, $_POST['p_name']);
$p_stock = mysqli_real_escape_string($con, $_POST['p_stock']);
$p_price = mysqli_real_escape_string($con, $_POST['p_price']);
$tax = mysqli_real_escape_string($con, $_POST['tax']);
$t_price = mysqli_real_escape_string($con, $_POST['t_price']);
$p_description = mysqli_real_escape_string($con, $_POST['p_description']);
$user_id = $_SESSION['uid'];
$target_dir = ADMIN_PRODUCT_UPLOAD_PATH;
// File upload logic fix
if(!empty($_FILES['product_image']['name'][0])) {
$filename = $_FILES['product_image']['name'][0];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$imagename = round(microtime(true)) . '.' . $ext;
$target_file = $target_dir . $imagename;
if(move_uploaded_file($_FILES['product_image']['tmp_name'][0], $target_file)) {
// Main Product Table Entry
$query = "INSERT INTO products(`name`, `category`, `sub_category`, `stock`, `price`, `tax`, `t_price`, `description`, `product_image`)
VALUES ('".$p_name."', '".$ct_id."', '".$cid."', '".$p_stock."', '".$p_price."', '".$tax."', '".$t_price."', '".$p_description."', '".$imagename."')";
$result = mysqli_query($con, $query);
$lastId = mysqli_insert_id($con);
if($lastId) {
$display_message = '<b style="color:green; margin-left:7%">Product Added Successfully</b>';
// Multiple Images Loop
$i = 0;
foreach ($_FILES['product_image']['name'] as $imaglist) {
if(!empty($imaglist)) {
$img_name = time() . "_" . $imaglist; // Unique name for each image
$img_temp = $_FILES['product_image']['tmp_name'][$i];
$target_file2 = $target_dir . $img_name;
if(move_uploaded_file($img_temp, $target_file2)) {
$mg_query = "INSERT INTO product_image(p_id, img_name) VALUES ('".$lastId."', '".$img_name."')";
mysqli_query($con, $mg_query);
}
}
$i++;
}
}
} else {
$display_message = '<b style="color:red; margin-left:7%">Failed to upload image. Check folder permissions.</b>';
}
} else {
$display_message = '<b style="color:red; margin-left:7%">Upload Image First</b>';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<?php
include 'includes/assets.php';
?>
<style>
.cke_notifications_area{
display: none;
}
</style>
</head>
<body class="skin-blue">
<div class="wrapper">
<?php
include 'includes/header.php';
?>
<!-- Left side column. contains the logo and sidebar -->
<?php
include 'includes/aside.php';
?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header" style="margin-left: 7%">
<h1><b>Add Product</b></h1>
<a href="view_product.php"> <button type="button" class="btn btn-primary" style="margin-left:38%">View Product</button></a>
</section>
<?php
echo $display_message;
?>
<!-- Main content -->
<section class="content" style="margin-left: 7%">
<div class="row">
<!-- left column -->
<div class="col-md-6">
<!-- general form elements -->
<div class="box box-primary">
<div class="box-header">
</div><!-- /.box-header -->
<?php //print_r($_GET); ?>
<!-- form start -->
<form role="form" method="post" action="" enctype="multipart/form-data">
<div class="box-body">
<div class="form-group">
<label for="exampleInputEmail1">Product Category</label>
<select class="form-control" id="category" placeholder="Product Type" name="ct_id">
<option>Select Category<small><b>*</b></small></option>
<?php
$selectFor = "SELECT * FROM category_type WHERE status = '1'";
$resultc = mysqli_query($con,$selectFor);
while($details2 = mysqli_fetch_array($resultc)){
?>
<option value="<?php echo $details2['id']; ?>"><?php echo $details2['category_type']; ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label for="exampleInputEmail1">Product Sub Category</label>
<select class="form-control" id="sub-category" placeholder="Product Type" name="cid">
<option>Select Sub Category<small><b>*</b></small></option>
</select>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Product Name</label>
<input type="text" name="p_name" class="form-control" placeholder="Product Name">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Product Stock</label>
<input type="text" name="p_stock" class="form-control" placeholder="Product Quantity">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Product Price</label>
<input type="text" name="p_price" class="form-control" placeholder="Product Price">
</div>
<div class="form-group">
<label for="tax">Tax(in percentage)</label>
<input type="text" name="tax" class="form-control" placeholder="Product tax">
</div>
<div class="form-group">
<label for="total-amount">Tax Added Price</label>
<input type="text" name="t_price" class="form-control" placeholder="Product Price including tax">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Product Description</label>
<textarea name="p_description" id="editor1" class="form-control" placeholder="Product Description"></textarea>
</div>
<div class="form-group" id="image-list">
<label for="exampleInputFile">Product Image</label>
<span class="add-multiple-image"><input type="button" value="Add Image"></span>
<input type="file" accept="image/*" name="product_image[]" id="exampleInputFile">
</div>
</div><!-- /.box-body -->
<div class="box-footer">
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div><!-- /.box -->
</div><!--/.col (left) -->
</div> <!-- /.row -->
</section><!-- /.content -->
</div><!-- /.content-wrapper -->
<?php
include 'includes/footer.php';
?>
</div><!-- ./wrapper -->
<!-- jQuery 2.1.3 -->
<script src="plugins/jQuery/jQuery-2.1.3.min.js"></script>
<!-- Bootstrap 3.3.2 JS -->
<script src="bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<!-- FastClick -->
<script src='plugins/fastclick/fastclick.min.js'></script>
<!-- AdminLTE App -->
<script src="dist/js/app.min.js" type="text/javascript"></script>
<!-- AdminLTE for demo purposes -->
<script src="dist/js/demo.js" type="text/javascript"></script>
<script src="https://cdn.ckeditor.com/4.22.1/standard/ckeditor.js"></script>
<script>
CKEDITOR.replace('editor1');
</script>
</body>
</html>
<script type="text/javascript">
var html_image = '<input type="file" accept="image/*" name="product_image[]" id="exampleInputFile">';
$("#category").change(function () {
var id = $('#category').val();
$.ajax({
type: "POST",
url: "get-category.php",
data: {
id: id
},
success: function (data) {
$('#sub-category').html(data);
},
error: function() {
$('#sub-category').html('<option>No Category to select</option>');
}
});
});
</script>