-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.php
55 lines (45 loc) · 1.86 KB
/
upload.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
<?php
require_once('./dao/productDAO.php');
if (isset($_POST['name'])) {
$name = $_POST['name'];
$price = $_POST['price'];
$rating = $_POST['rating'];
$thumbnail = $_POST['thumbnail'];
$pictures = $_POST['pictures'];
$description = $_POST['description'];
$category = $_POST['category'];
$folder = "images/";
$thumbPath = $folder . basename($_FILES["thumbnail"]["name"]);
$picsPath = $folder . basename($_FILES["pictures"]["name"]);
$extensions = array('gif', 'png', 'jpg');
$thumbExtension = pathinfo($thumbPath, PATHINFO_EXTENSION);
$picsExtension = pathinfo($picsPath, PATHINFO_EXTENSION);
if (in_array($thumbExtension, $extensions) && in_array($picsExtension, $extensions)) {
if (!file_exists($thumbPath) && !file_exists($picsPath)) {
if (move_uploaded_file($_FILES["thumbnail"]["tmp_name"], $thumbPath)) {
if (move_uploaded_file($_FILES["pictures"]["tmp_name"], $picsPath)) {
$productDAO = new productDAO();
$product = new Product(0, $name, $price, $rating, $description, $thumbPath, $picsPath, $category);
$addProd = $productDAO->addProduct($product);
echo "Product Added Successfully";
echo $addProd;
} else {
print "Image not uploaded! Unexpected error occured.";
http_response_code(500);
}
} else {
print "Image not uploaded! Unexpected error occured.";
http_response_code(501);
}
} else {
print "The Image already exists! Choose another image";
http_response_code(502);
}
} else {
print "Not an Image file";
http_response_code(502);
}
} else {
print "Invalid Form";
http_response_code(502);
}