-
Notifications
You must be signed in to change notification settings - Fork 6
/
picadd.php
52 lines (38 loc) · 1.47 KB
/
picadd.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
<?php
if(isset($_POST['upload']) && isset($_FILES['my_image'])){
include "db_conn.php";
echo "<pre>";
print_r($_FILES['my_image']);
echo "</pre>";
$img_name = $_FILES['my_image']['name'];
$img_size = $_FILES['my_image']['size'];
$tmp_name = $_FILES['my_image']['tmp_name'];
$error = $_FILES['my_image']['error'];
if ($error === 0){
if ($img_size > 262144 ){
$em = "Sorry,your file is too large..";
header("Location: photo.php?error=$em");
}else{
$img_ex = pathinfo($img_name, PATHINFO_EXTENSION);
$img_ex_lc = strtolower($img_ex);
$allowed_exs = array("jpg","jpeg","png");
if(in_array($img_ex_lc,$allowed_exs)){
$new_img_name = uniqid("IMG-",true).'.'.$img_ex_lc;
$img_upload_path = 'Images/'.$new_img_name;
move_uploaded_file($tmp_name, $img_upload_path);
$sql = "INSERT INTO images (image_url)
VALUES('$new_img_name')";
mysqli_query($conn, $sql);
header("Location: photo.php");
}else{
$em = "You can't upload files of this type..!!";
header("Location: photo.php?error=$em");
}
}
}else{
$em = "unknown error occurred..!!";
header("Location: managemem.php?error=$em");
}
}else{
header("Location: managemem.php");
}