我有一个将一个图像放入数据库的表单,我想一次放多个。我的表单中有多个输入。我在这里看过类似的主题,但它没有帮助。
<form method="post" role="form" action="" enctype="multipart/form-data">
<input type="file" class="form-control" id="files" name="photo" required multiple>
<?php
if(isset($_POST['submit'])){
if (isset($_FILES['photo'])){
include 'dbconnect.php';
$target = "img/"; //This is the directory where images will be saved
$target_file = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form
$ad_user = $_POST['user_id'];
$ad_phone = $_POST['telephone'];
$ad_title = $_POST['title'];
$ad_price = $_POST['price'];
$ad_categorie = $_POST['category'];
$ad_city = $_POST['ville'];
$ad_pays = $_POST['pays'];
$ad_description = $_POST['description'];
$ad_photo= $target . ($_FILES['photo']['name']);
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target_file)) { //Tells you if its all ok
} else { //Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
$sql = "INSERT INTO ads (title, price, description, city, pays, urlimage, user, phone, category) VALUES ('$ad_title', '$ad_price', '$ad_description','$ad_city', '$ad_pays', '$ad_photo', '$ad_user', '$ad_phone', '$ad_categorie ') ";
$conn->query($sql);
//Writes the photo to the server
header('db.php');
$conn->close();
}
}
&GT;
这是我在表单和php中的文件输入。有人可以帮忙吗?感谢名单