I have an error when the form is submitted. I try to get an image upload in the input image1 I have specified multipart/form-data , and specified the name value of the input : image1 I also tried with post method and get method but $_FILES still empty the error is : Notice: Undefined index: image1
Here is the HTML code
<form enctype="multipart/form-data" class="formulaire" method="get" action="../controllers/import_controller.php">
<table class="table">
<tr bgcolor="#f39c12">
<th align="center" width="33%">CATEGORIE</th>
<th align="center" width="33%">SOUS CATEGORIE</th>
</tr>
<tr>
<td><select type="text" name="categorie" placeholder="Categorie" onchange="liste_sous_categorie(this.value)" required/><?php liste_categorie(); ?></select></td>
<td><div id="liste_sous_categorie"><select required/></select></div></td>
</tr>
</table>
<table id="image_add" class="table">
<tr>
<td><span>LIBELLE</span></td>
<td><input type="text" name="libelle" required/></td>
</tr>
<tr>
<td><span>DESCRIPTION</span></td>
<td><textarea name="description" required></textarea></td>
</tr>
<tr>
<td><span>PRIX</span></td>
<td><input min="1" type="number" name="prix" required/></td>
</tr>
<tr>
<td><span>STOCK</span></td>
<td><input min="1" type="number" name="stock" required/></td>
</tr>
<tr>
<td><span>IMAGE 1</span></td>
<td><input type="file" name="image1" accept="image/*" required/></td>
</tr>
</table>
<input type="hidden" value="1" name="nbre_image_article" id="nbre_image_article">
<input type="hidden" value="1" name="article_add">
<center><input align="center" type="submit" value="VALIDER" class="btn btn-primary" style="margin-right: 5px;"></input><i class="fa fa-task"></i></center>
<br>
</form>
And the PHP code
if(isset($_GET['article_add']))
{
$libelle=addslashes(htmlentities($_GET['libelle']));
$description=addslashes(htmlentities($_GET['description']));
$prix=$_GET['prix'];
$stock=$_GET['stock'];
$sous_categorie_id_sous_categorie=$_GET['sous_categorie'];
$nbre_image_article=$_GET['nbre_image_article'];
session_start();
$uploaddir = '../../views/images/articles/';
$uploadfile = $uploaddir . basename($_FILES['image1']['name']);
echo $_FILES['image1']['error'];
echo '<pre>';
if (move_uploaded_file($_FILES['image1']['tmp_name'], $uploadfile)) {
echo "Le fichier est valide, et a été téléchargé
avec succès. Voici plus d'informations :\n";
} else {
echo "Attaque potentielle par téléchargement de fichiers.
Voici plus d'informations :\n";
}
}