-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupload_productback.php
81 lines (70 loc) · 2.13 KB
/
upload_productback.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
<?php
session_start();
include('./conn.php');
if(isset($_POST['submit'])){
$productType = $_POST['type'];
$productName = $_POST['pname'];
$productInfo = $_POST['pinfo'];
$productPrice =$_POST['price'];
// $user = $_SESSION['Username'];
$fid = $_SESSION['id'];
$sql = "INSERT INTO `fproduct`(`fid`,`product`, `pcat`, `pinfo`, `price`)
VALUES ('$fid', '$productName', '$productType', '$productInfo', '$productPrice')";
$result = mysqli_query($conn, $sql);
if(!$result)
{
$_SESSION['message'] = "Unable to upload Product !!!";
header("Location: Login/error.php");
}
else {
$_SESSION['message'] = "successfull !!!";
}
$pic = $_FILES['productPic'];
$picName = $pic['name'];
$picTmpName = $pic['tmp_name'];
$picSize = $pic['size'];
$picError = $pic['error'];
$picType = $pic['type'];
$picExt = explode('.', $picName);
$picActualExt = strtolower(end($picExt));
$allowed = array('jpg','jpeg','png');
if(in_array($picActualExt, $allowed))
{
if($picError === 0)
{
$_SESSION['productPicId'] = $_SESSION['id'];
$picNameNew = $productName.$_SESSION['productPicId'].".".$picActualExt ;
$_SESSION['productPicName'] = $picNameNew;
$_SESSION['productPicExt'] = $picActualExt;
$picDestination = "img/productImages/".$picNameNew;
move_uploaded_file($picTmpName, $picDestination);
$id = $_SESSION['id'];
$sql = "UPDATE fproduct SET picStatus=1, pimage='$picNameNew' WHERE product='$productName';";
$result = mysqli_query($conn, $sql);
if($result)
{
$_SESSION['message'] = "Product Image Uploaded successfully !!!";
header("Location:bpost.php");
}
else
{
//die("bad");
$_SESSION['message'] = "There was an error in uploading your product Image! Please Try again!";
header("Location: Login/error.php");
}
}
}
else
{
$_SESSION['message'] = "You cannot upload files with this extension!!!";
header("Location: Login/error.php");
}
}
// function dataFilter($data)
// {
// $data = trim($data);
// $data = stripslashes($data);
// $data = htmlspecialchars($data);
// return $data;
// }
?>