-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.php
45 lines (36 loc) · 1.08 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
<?php
if(isset($_POST['submit'])) {
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES['image']['name']);
$success = 1;
$imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
if(isset($_POST['submit'])) {
$check = getimagesize($_FILES['image']['tmp_name']);
if($check !== false) {
$success = 1;
} else {
$sucess = 0;
}
}
if(file_exists($target_file)) {
$_SESSION['message'] = "File already exists.";
$success = 0;
}
if($_FILES['image']['size'] > 500000) {
$_SESSION['message'] = "File size limit exceeded.";
$success = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg") {
$_SESSION['message'] = "Invalid file type.";
$success = 0;
}
if($success === 1) {
$target_file = $target_dir . $poll_id . '.' . $imageFileType;
if(move_uploaded_file($_FILES['image']['tmp_name'], $target_file)) {
$_SESSION['message'] = "File uploaded.";
} else {
$_SESSION['message'] = "File upload failed.";
}
}
}
?>