i have a problem in uploading multiple file can anyone help me to solve this problem?
here is my index.php
<!DOCTYPE html>
<head>
<title>MySQL file upload example</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="add_file2.php" method="post" enctype="multipart/form-data">
<input type="file" name="uploaded_file[0]"><br>
<input type="file" name="uploaded_file[1]"><br>
<input type="file" name="uploaded_file[2]"><br>
<input type="submit" value="Upload file">
</form>
<p>
<a href="list.php">See all files</a>
</p>
</body>
</html>
add_file2.php
<?php
$dbLink = new mysqli('localhost', 'root', '', 'sampleupload');
if(mysqli_connect_errno()) {
die("MySQL connection failed: ". mysqli_connect_error());
}
for($c=0;$c<8;$c++){
if(isset($_FILES['uploaded_file['.$c.']'])) {
if($_FILES['uploaded_file['.$c.']']['error'] == 0) {
$name = $dbLink->real_escape_string($_FILES['uploaded_file['.$c.']']['name']);
$mime = $dbLink->real_escape_string($_FILES['uploaded_file['.$c.']']['type']);
$data = $dbLink->real_escape_string(file_get_contents($_FILES ['uploaded_file['.$c.']']['tmp_name']));
$size = intval($_FILES['uploaded_file['.$c.']']['size']);
$query = "
INSERT INTO `file` (
`name`, `mime`, `size`, `data`, `created`
)
VALUES (
'{$name}', '{$mime}', {$size}, '{$data}', NOW()
)";
}
$result = $dbLink->query($query);
if($result) {
echo 'Success! Your file was successfully added!';
}
else {
echo 'Error! Failed to insert the file'
. "<pre>{$dbLink->error}</pre>";
}
}
else {
echo 'An error accured while the file was being uploaded. '
. 'Error code: '. intval($_FILES['uploaded_file']['error']);
}
}
echo '<p>Click <a href="index.php">here</a> to go back</p>';
?>