Well, my request is that each checked check box sends the chosen image, but I don't know of any other way than the "move_uploaded_file". Maybe it is only my code that is needed or simply my request cannot work. I thought of an option that copies the image and sends it to the requested folders. Thank you for reading my question.
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);
}
AND 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>
Aucun commentaire:
Enregistrer un commentaire