-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateCategory.php
38 lines (37 loc) · 1.43 KB
/
createCategory.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
<?php
include 'main.php';
$uploadOk = 1;
$allowed = array('jpg', 'jpeg', 'gif', 'png', strtolower(end(explode('.', $profile_pic))));
$file_name = $_FILES['post_img']['name'];
$file_extn = strtolower(end(explode('.', $file_name)));
$file_temp = $_FILES['post_img']['tmp_name'];
$check = getimagesize($_FILES["post_img"]["tmp_name"]);
if($check !== false) {
//echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
// echo "File is not an image.";
$uploadOk = 0;
}
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
if (in_array($file_extn, $allowed) === true && $uploadOk == 1) {
uploadCategory($_POST['post_name'], $file_temp, $file_extn, $con);
} elseif (in_array($file_extn, $allowed) === false) {
echo 'Incorrect file type ';
echo implode(',', $allowed);
} else {
echo 'fejl';
}
function uploadCategory($name, $file_temp, $file_extn, $con)
{
$file_path = 'uploads/' . substr(md5(time()), 0, 10) . '.' . $file_extn;
move_uploaded_file($file_temp, $file_path);
$stmt = $con->prepare('INSERT INTO categories (name, icon) VALUES (?, ?)');
$stmt->bind_param('ss', $name, $file_path);
$stmt->execute();
$stmt->close();
header('Location: adminPanel.php');
}