-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathupload.php
67 lines (56 loc) · 1.66 KB
/
upload.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<html>
<body>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
min-height: 100vh;
}
</style>
<form action="" method="post" enctype="multipart/form-data">
</form>
</body>
</html>
<?php
if (isset($_POST['submit']) && isset($_FILES['uploadfile'])) {
include "db_conn.php";
echo "<pre>";
print_r($_FILES['uploadfile']);
echo "</pre>";
$img_name = $_FILES['uploadfile']['name'];
$img_size = $_FILES['uploadfile']['size'];
$tmp_name = $_FILES['uploadfile']['tmp_name'];
$error = $_FILES['uploadfile']['error'];
if ($error === 0) {
if ($img_size > 129000) {
$em = "Sorry, your file is too large.";
header("Location: index2.html?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 = 'uploads/'.$new_img_name;
move_uploaded_file($tmp_name, $img_upload_path);
echo "<img src='$img_upload_path' height='300' width='300'/>";
echo "!!..'Your file uploaded successfully'..!!";
// Insert into Database
$sql = "INSERT INTO images(image_url)
VALUES('$new_img_name')";
mysqli_query($conn, $sql);
//header("Location: view.php");
}else {
$em = "You can't upload files of this type";
header("Location: index2.php?error=$em");
}
}
}else {
$em = "unknown error occurred!";
header("Location: index2.php?error=$em");
}
}else {
header("Location: index2.php");
} ?>