简单明了。我想创建一个表单,首先将所有字段值插入MySQL数据库。其次,我想为用户提供上传多张图片的选项。但下面的代码不会将图像插入数据库。我完全迷失了。不知道这段代码还有什么问题。
<form action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?> method="post" enctype="multipart/form-data">
<p><input type="file" name="file_array[]"></p>
<p><input type="file" name="file_array[]"></p>
<p><input type="file" name="file_array[]"></p>
<input type="FirstN" name="Firstname" >
<input type="LastN" name="Lastname" >
<input type="submit" value="Upload all files">
</form>
<?php
if(isset($_POST['submit'])) {
if(isset($_FILES['file_array'])) {
$name_array = $_FILES['file_array']['name'];
$tmp_name_array = $_FILES['file_array']['tmp_name'];
$type_array = $_FILES['file_array']['type'];
$size_array = $_FILES['file_array']['size'];
$error_array = $_FILES['file_array']['error'];
for($i = 0; $i < count($tmp_name_array); $i++) {
if(move_uploaded_file($tmp_name_array[$i], "test_uploads/".$name_array[$i])) {
echo $name_array[$i]." upload is complete<br>";
} else {
echo "move_uploaded_file function failed for ".$name_array[$i]."<br>";
}
}
}
$sql = "INSERT INTO image, FirstName, LastName VALUES ('{FirstN}','{LastN}','{file_array}')";
}
?>