This repository was archived by the owner on Jul 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_upload.php
More file actions
57 lines (48 loc) · 1.74 KB
/
image_upload.php
File metadata and controls
57 lines (48 loc) · 1.74 KB
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
<?php
// #####################################
//# INTITIALIZATION #
// #####################################
include "../inc/dbinfo.inc";
require_once 'vendor/autoload.php';
session_start();
$sql_id = $_SESSION['sql_id'];
$categories = $_SESSION["categories"];
$cat_index = $_POST["cats"];
$size = is_array($cat_index) ? count($cat_index) : 0 ;
//$purchasable = $_SESSION["purchasable"];
$target_name = $_POST["name"];
$target_file = $_POST["path"];
// #####################################
// # MySQL calls
// #####################################
// Create connection
$conn = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// #####################################
// # Insert Image to DB #
// #####################################
//Upload the images to the Image Database
$sql = "INSERT INTO UploadedImages (user_id, image_name, filepath) values ('$sql_id', '$target_name', '$target_file')";
mysqli_query($conn, $sql);
// #####################################
// # Categories Addes to Images #
// #####################################
$sql = "SELECT image_id FROM UploadedImages WHERE image_name='$target_name';";
$result = mysqli_query($conn, $sql);
$row = $result->fetch_assoc();
$image_id = $row['image_id'];
if($size > 0){
for($i = 0; $i < $size; $i++){
$temp_cat = $categories[$cat_index[$i]]['Name'];
$sql = "INSERT INTO ImageCategories (image_id, category) values ('$image_id', '$temp_cat')";
mysqli_query($conn, $sql);
}
} else {
$sql = "INSERT INTO ImageCategories (image_id, category) values ('$image_id', 'Uncategorized')";
mysqli_query($conn, $sql);
}
mysqli_close($conn);
?>