-
Notifications
You must be signed in to change notification settings - Fork 0
/
editProductImage.php
37 lines (27 loc) · 1.04 KB
/
editProductImage.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
<?php
require_once 'core.php';
$valid['success'] = array('success' => false, 'messages' => array());
if($_POST) {
$productId = $_POST['productId'];
$type = explode('.', $_FILES['editProductImage']['name']);
$type = $type[count($type)-1];
$url = '../assests/images/stock/'.uniqid(rand()).'.'.$type;
if(in_array($type, array('gif', 'jpg', 'jpeg', 'png', 'JPG', 'GIF', 'JPEG', 'PNG'))) {
if(is_uploaded_file($_FILES['editProductImage']['tmp_name'])) {
if(move_uploaded_file($_FILES['editProductImage']['tmp_name'], $url)) {
$sql = "UPDATE product SET product_image = '$url' WHERE product_id = $productId";
if($connect->query($sql) === TRUE) {
$valid['success'] = true;
$valid['messages'] = "Successfully Updated";
} else {
$valid['success'] = false;
$valid['messages'] = "Error while updating product image";
}
} else {
return false;
} // /else
} // if
} // if in_array
$connect->close();
echo json_encode($valid);
} // /if $_POST