-
Notifications
You must be signed in to change notification settings - Fork 0
/
img_process.php
47 lines (40 loc) · 1.21 KB
/
img_process.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
<?php
if (isset($_POST['submit']) && isset($_FILES['image'])) {
include "conn.php";
echo "<pre>";
print_r($_FILES['image']);
echo "</pre>";
$img_name = $_FILES['image']['name'];
$img_size = $_FILES['image']['size'];
$img_tmp = $_FILES['image']['tmp_name'];
$error = $_FILES['image']['error'];
if ($error === 0) {
if ($img_size > 1000000) {
$em = "please upload image less than 100000 kb";
header("Location: error.php?error=$em");
}else {
$img_ext = pathinfo($img_name, PATHINFO_EXTENSION);
$img_low_ext = strtolower($img_ext);
$allowed_ext = array("jpg", "jpeg", "png");
if (in_array($img_low_ext, $allowed_ext)) {
$new_img_name = uniqid("IMG-", true).'.'.$img_ext;
$img_upload_path = 'uploads/'.$new_img_name;
move_uploaded_file($img_tmp, $img_upload_path);
// Insert into Database
$sql = "INSERT INTO `img_url` ( `img_url`) VALUES ('$new_img_name')";
mysqli_query($db, $sql);
header("Location: index.php");
}else {
$em = "Your file is not an image";
header("Location: error.php?error=$em");
}
}
}else {
$em = "undfinded error";
header("Location: error.php?error=$em");
}
}else {
$em = "madachud er error";
header("Location: error.php?error=$em");
}
?>