forked from Mahin077/EducationUnlocked
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uploadCategory.php
35 lines (26 loc) · 1007 Bytes
/
uploadCategory.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
<?PHP
if (isset($_POST['submit']) && isset($_FILES['my_image'])) {
include("connect.php");
$Topic_name=$_POST['name'];
$image_name = $_FILES['my_image']['name'];
$tmp_name = $_FILES['my_image']['tmp_name'];
$error = $_FILES['my_image']['error'];
if ($error === 0) {
$image_ex = pathinfo($image_name,PATHINFO_EXTENSION);
$image_ex_lc = strtolower($image_ex);
$allowed_exs = array("jpg", 'jpeg', 'png');
if (in_array($image_ex_lc, $allowed_exs)) {
$new_image_name=$image_name ;
$image_upload_path = 'uploads/'.$new_image_name;
move_uploaded_file($tmp_name, $image_upload_path);
$sql = "INSERT INTO `cards`(`name`, `images`) VALUES('$Topic_name','$new_image_name')";
mysqli_query($conn, $sql);
header("Location:categoryUp.php");
}else {
$em = "You can't upload files of this type";
header("Location:categoryUp.php?error=$em");
}
}
}else{
header("Location: categoryUp.php");
}