So iv been trying to upload an image into my SQL database and display it on a diffrent page, the display part works fine as long as I upload it manually via the database (type longblob) but if i try to store it using the <label for="image">image</label> <input type="file" name="image" id="image" />
whenever i try to display it i get the error if an empty square which means im not storing anything. The thing is i have found a solution, since every one is doing it with the addslashes(file_get_contents($_FILES['image']['tmp_name']));
but i dont know how to implement it. In the few ways i tried it i get a "Unidentified array key ['image']EVERYTIME. so here is my code (its separated on 2 different pages, ill just show the functions) and i really need your help on this one.
This is addpromo.php:
*testing if everything isset and not empty* {
$promotion = new promotion(
$_POST['id_artiste'],
$_POST['id_produit'],
$_POST['nom'],
$_POST['reduction'],
$_POST['duree'],
$_POST['description'],
$_POST['image'],
);
$promotionC->ajouterpromotion($promotion);
header('Location:afficherpromo.php');
}
else
$error = "Missing information";
}
And this is The insert function in PromoC.php:
function ajouterpromotion($promotion) {
$sql = "INSERT INTO promotion (id_artiste, id_produit, nom, reduction, duree, description, image) VALUES (:id_artiste, :id_produit, :nom, :reduction, :duree, :description, :image)";
$db = config::getConnexion();
try{
$query = $db->prepare($sql);
$query->execute([
'id_artiste'=>$promotion->getida(),
'id_produit' => $promotion->getprod(),
'nom' => $promotion->getno(),
'reduction' => $promotion->getred(),
'duree' => $promotion->getdur(),
'description'=> $promotion->getdesc(),
'image' => $promotion->getima(),
]);
}
catch(Exception $e) {
echo 'Erreur: '.$e->getMessage();
}
}
Everything works exept for the image