-
Notifications
You must be signed in to change notification settings - Fork 1
/
addProductProcess.php
99 lines (69 loc) · 2.76 KB
/
addProductProcess.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
session_start();
require "connection.php";
$email = $_SESSION["u"]["email"];
$category = $_POST["ca"];
$brand = $_POST["b"];
$model = $_POST["m"];
$title = $_POST["t"];
$condition = $_POST["con"];
$clr = $_POST["col"];
$qty = $_POST["qty"];
$cost = $_POST["cost"];
$dwc = $_POST["dwc"];
$doc = $_POST["doc"];
$desc = $_POST["desc"];
$mhb_rs = Database::search("SELECT * FROM `model_has_brand` WHERE
`model_model_id`='".$model."' AND `brand_brand_id`='".$brand."'");
$mhb_id ;
if($mhb_rs->num_rows > 0){
$mhb_data = $mhb_rs->fetch_assoc();
$mhb_id = $mhb_data["id"];
}else{
Database::iud("INSERT INTO `model_has_brand`(`model_model_id`,`brand_brand_id`)
VALUES ('".$model."','".$brand."')");
$mhb_id = Database::$connection->insert_id;
}
$d = new DateTime();
$tz = new DateTimeZone("Asia/Colombo");
$d->setTimezone($tz);
$date = $d->format("Y-m-d H:i:s");
$status = 1;
Database::iud("INSERT INTO `product`(`price`,`qty`,`description`,`title`,`datetime_added`,
`delivery_fee_colombo`,`delivery_fee_other`,`category_cat_id`,`model_has_brand_id`,`color_clr_id`,
`status_status_id`,`condition_condition_id`,`users_email`) VALUES ('".$cost."','".$qty."',
'".$desc."','".$title."','".$date."','".$dwc."','".$doc."','".$category."','".$mhb_id."',
'".$clr."','".$status."','".$condition."','".$email."')");
$product_id = Database::$connection->insert_id;
$length = sizeof($_FILES);
if($length <= 3 && $length > 0){
$allowed_img_extentions = array("image/jpg","image/jpeg","image/png","image/svg+xml");
for($x = 0;$x < $length;$x++){
if(isset($_FILES["img".$x])){
$img_file = $_FILES["img".$x];
$file_extention = $img_file["type"];
if(in_array($file_extention,$allowed_img_extentions)){
$new_img_extention;
if($file_extention == "image/jpg"){
$new_img_extention = ".jpg";
}else if($file_extention == "image/jpeg"){
$new_img_extention = ".jpeg";
}else if($file_extention == "image/png"){
$new_img_extention = ".png";
}else if($file_extention == "image/svg+xml"){
$new_img_extention = ".svg";
}
$file_name = "resourses//products//".$title."_".$x."_".uniqid().$new_img_extention;
move_uploaded_file($img_file["tmp_name"],$file_name);
Database::iud("INSERT INTO `product_img`(`img_path`,`product_id`)
VALUES ('".$file_name."','".$product_id."')");
echo ("success");
}else{
echo ("Not an allowed image type.");
}
}
}
}else{
echo ("Invalid Image Count");
}
?>