-
Notifications
You must be signed in to change notification settings - Fork 46
/
upload.php
78 lines (70 loc) · 2.29 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
68
69
70
71
72
73
74
75
76
77
78
<?php
$allowedTypes = array(
'image/png',
'image/jpg',
'image/jpeg'
);
if ( $_FILES['photo'] ) {
$totalFiles = count($_FILES['photo']['name']);
for($i=0;$i<$totalFiles;$i++){
if ( in_array( $_FILES['photo']['type'][$i], $allowedTypes ) !== false && $_FILES['photo']['size'][$i] < 5 * 1024 * 1024 ) {
echo move_uploaded_file( $_FILES['photo']['tmp_name'][$i], "./files/" . $_FILES['photo']['name'][$i] );
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Form Example</title>
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
<link rel="stylesheet" href="//cdn.rawgit.com/necolas/normalize.css/master/normalize.css">
<link rel="stylesheet" href="//cdn.rawgit.com/milligram/milligram/master/dist/milligram.min.css">
<style>
body {
margin-top: 30px;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="column column-60 column-offset-20">
<h2>File Upload</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquid magnam fugiat doloribus officia. Vero
illum debitis ipsam necessitatibus eaque sed.</p>
<?php
if ( isset( $_POST['submit'] ) ):
?>
<pre>
<p>
<?php
print_r( $_POST );
print_r( $_FILES );
?>
</p>
</pre>
<?php
endif;
?>
</div>
</div>
<div class="row">
<div class="column column-60 column-offset-20">
<form method="POST" enctype="multipart/form-data">
<label for="fname">First Name</label>
<input type="text" name="fname" id="fname">
<label for="lname">Last Name</label>
<input type="text" name="lname" id="lname">
<label for="photo">Photo</label>
<input type="file" name="photo[]" id="photo"><br/>
<input type="file" name="photo[]" id="photo"><br/>
<input type="file" name="photo[]" id="photo"><br/>
<button type='submit' name="submit" value="submit">Submit</button>
</form>
</div>
</div>
</div>
</body>
</html>