-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupload.php
More file actions
36 lines (30 loc) · 1.14 KB
/
upload.php
File metadata and controls
36 lines (30 loc) · 1.14 KB
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
<?php
if(isset($_FILES['file'])) {
$file = $_FILES['file'];
// File Properties
$file_name = $file['name'];
$file_tmp = $file['tmp_name'];
$file_size = $file['size'];
$file_error = $file['error'];
$fileType = $file['file']['type'];
//Work out the file extension
$file_ext = explode('.', $file_name);
$file_ext = strtolower(end($file_ext));
$allowed = array('jpg', 'jpeg', 'pdf', 'png');
if (in_array($file_ext, $allowed)) {
if ($fileError === 0) {
if ($fileSize <= 50000) {
$file_name_new = uniqid('', true).'.'. $file_ext;
$file_destination = 'uploads/' . $file_name_new;
if(move_uploaded_file($file_tmp, $file_destination)) {
echo $file_destination;
}
} else {
echo "Your file is too large.";
}
}
} else {
echo "You can't upload files of this type.";
}
}
?>