-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
75 lines (54 loc) · 2.05 KB
/
Copy pathupload.php
File metadata and controls
75 lines (54 loc) · 2.05 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
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
68
69
70
71
72
73
74
75
<?php
$maxSize = 1000000;
$uploadDirectory = 'upload/';
$extensions = ['png', 'gif', 'jpg'];
/*if (isset($_POST['submit'])) {
foreach ($_FILES as $value) {
foreach ($value as $property) {
foreach ($property as $key => $value2) {
$fileName = $value['name'][$value2];
$fileSize = $value['size'][$value2];
$extension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
$newFileName = 'image' . uniqid() . '.' . $extension;
if (!in_array($extension, $extensions)) {
echo "L'extension du fichier n'est pas autorisée";
}
if ($fileSize > $maxSize) {
echo "Le fichier est trop lourd";
}
$destination = $uploadDirectory.$newFileName;
move_uploaded_file($value['tmp_name'][$value2], $destination);
}
}
}
}*/
if (isset($_POST['submit'])) {
$errors = [];
foreach ($_FILES as $files) {
foreach ($files['name'] as $fileName) {
$extension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
}
if (!in_array($extension, $extensions)) {
$errors['extension'] = "L'extension du fichier n'est pas autorisée";
echo $errors['extension'];
}
foreach ($files['size'] as $fileSize) {
if ($fileSize > $maxSize) {
$errors['size'] = "Le fichier est trop lourd";
echo $errors['size'];
}
}
if (empty($errors)) {
foreach ($files['tmp_name'] as $fileTmp) {
$newFileName = 'image' . uniqid() . '.' . $extension;
$destination = $uploadDirectory.$newFileName;
if(move_uploaded_file($fileTmp, $destination)) {
echo "Fichiers importés avec succès";
header("Location: form.php");
} else {
echo "Echec de l'envoi";
}
}
}
}
}