好吧,我的要求是每个选中的复选框都会发送所选的图像,但我不知道除了“move_uploaded_file”之外还有什么其他方式。也许只是需要我的代码,或者只是我的请求无法工作。我想到了一个选项,可以复制图像并将其发送到请求的文件夹。感谢您阅读我的问题。
PHP
// Create database connection
$db = mysqli_connect("localhost", "root", "", "photos");
// Initialize message variable
$msg = "";
// If upload button is clicked ...
if (isset($_POST['upload'])) {
// Get image name
$image = $_FILES['image']['name'];
//GET image nom
$image_nom = mysqli_real_escape_string($db, $_POST['image_nom']);
// Get text
$image_text = mysqli_real_escape_string($db, $_POST['image_text']);
// image file directory
if (isset($_POST['combat'])) {
$target = "combat/images/".basename($image);
if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
$msg = "Image uploaded successfully";
}else{
$msg = "Failed to upload image";
}
$sql = "INSERT INTO images (image, image_nom, image_text) VALUES ('$image', '$image_nom', '$image_text')";
// execute query
mysqli_query($db, $sql);
}
if (isset($_POST['personnage'])) {
$targetp = "search/personnages/".basename($image);
if (move_uploaded_file($_FILES['image']['tmp_name'], $targetp)) {
$msg = "Image uploaded successfully";
}else{
$msg = "Failed to upload image";
}
$sql = "INSERT INTO personnage (image_personnage, image_nom_personnage, image_text_personnage) VALUES ('$image', '$image_nom', '$image_text')";
// execute query
mysqli_query($db, $sql);
}
和 HTML
<form method='post' action='' enctype='multipart/form-data'>
<input type="checkbox" id="combat" name="combat">
<label for="combat">Combat</label></br>
<input type="checkbox" id="personnage" name="personnage">
<label for="personnage">Personnage</label></form>
守着星空守着你