-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
52 lines (39 loc) · 1.18 KB
/
index.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
<!doctype html>
<html>
<head>
<title>Upload Multiple Image files to the Database using PDO - PHP</title>
<?php
include "config.php";
if(isset($_POST['submit'])){
// Count total files
$countfiles = count($_FILES['files']['name']);
// Prepared statement
$query = "INSERT INTO images (name,image) VALUES(?,?)";
$statement = $conn->prepare($query);
// Loop all files
for($i=0;$i<$countfiles;$i++){
// File name
$filename = $_FILES['files']['name'][$i];
// Get extension
$ext = end((explode(".", $filename)));
// Valid image extension
$valid_ext = array("png","jpeg","jpg");
if(in_array($ext, $valid_ext)){
// Upload file
if(move_uploaded_file($_FILES['files']['tmp_name'][$i],'upload/'.$filename)){
// Execute query
$statement->execute(array($filename,'upload/'.$filename));
}
}
}
echo "File upload successfully";
}
?>
</head>
<body>
<form method='post' action='' enctype='multipart/form-data'>
<input type='file' name='files[]' multiple />
<input type='submit' value='Submit' name='submit' />
</form>
</body>
</html>