-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.php
42 lines (33 loc) · 1.36 KB
/
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
<?php
if (isset($_POST['prefix'])){ echo "My UserId".$_POST['prefix']. "<br/>"; }
print_r($_FILES);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_FILES['files'])) {
$errors = [];
$path = 'uploads/';
$extensions = ['jpg', 'jpeg', 'png', 'gif'];
$all_files = count($_FILES['files']['tmp_name']);
for ($i = 0; $i < $all_files; $i++) {
// filename = date + userid + filename
$file_name = $_POST['prefix']."_".$_FILES['files']['name'][$i];
echo $file_name; //????
$file_tmp = $_FILES['files']['tmp_name'][$i];
$file_type = $_FILES['files']['type'][$i];
$file_size = $_FILES['files']['size'][$i];
$file_ext = strtolower(end(explode('.', $_FILES['files']['name'][$i])));
// $file : path + name
$file = $path . $file_name;
if (!in_array($file_ext, $extensions)) {
$errors[] = 'Extension not allowed: ' . $file_name . ' ' . $file_type;
}
if ($file_size > 2097152) {
$errors[] = 'File size exceeds limit: ' . $file_name . ' ' . $file_type;
}
if (empty($errors)) {
echo "XXX". $file_tmp;
move_uploaded_file($file_tmp, $file);
}
}
if ($errors) print_r($errors);
}
}