Php 未定义索引:$\u文件中的image1
我在提交表单时出错。 我尝试在输入图像1中上传图像 我已经指定了多部分/表单数据,并指定了输入的名称值:image1 我还尝试了post方法和get方法,但$\u文件仍然为空 错误是:注意:未定义索引:image1 下面是HTML代码Php 未定义索引:$\u文件中的image1,php,image,file,Php,Image,File,我在提交表单时出错。 我尝试在输入图像1中上传图像 我已经指定了多部分/表单数据,并指定了输入的名称值:image1 我还尝试了post方法和get方法,但$\u文件仍然为空 错误是:注意:未定义索引:image1 下面是HTML代码 <form enctype="multipart/form-data" class="formulaire" method="get" action="../controllers/import_controller.php">
<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>
分类
分类苏
诽谤
描述
大奖赛
股票
图1
还有PHP代码
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";
}
}
if(isset($\u GET['article\u add']))
{
$libelle=addslashes(htmlentities($_GET['libelle']);
$description=addslashes(htmlentities($_GET['description']);
$prix=$_GET['prix'];
$stock=$_GET['stock'];
$sous\u categorie\u id\u sous\u categorie=$\u GET['sous\u categorie'];
$nbre_image_article=$_GET['nbre_image_article'];
会话_start();
$uploaddir='../../views/images/articles/';
$uploadfile=$uploaddir.basename($_FILES['image1']['name']);
echo$_文件['image1']['error'];
回声';
如果(移动上传的文件($上传文件['image1']['tmp\u名称'],$uploadfile)){
回音“我最爱你,我最爱你”
avec Success.Voici附加信息:\n”;
}否则{
回声“附加的潜力”。
Voici加d’信息:\n”;
}
}
上传文件需要使用POST方法,而不是GET方法
因此,您需要将表单的方法更改为method=“post”
您还需要将$\u GET
的所有实例更改为$\u POST
- 在您喜爱的编辑器中快速查找和替换,将立即更改这些编辑器
将表单方法更改为POST
而不是GET
尝试仅打印$\u文件
,并检查它有什么?也许你得到了答案,或者至少你可以把它放在这里得到答案。另外,get
需要更改为post
我尝试了post方法,我注意到我的代码中有两个相同的应答器,这就是文件没有上传的原因。谢谢你的记录,我提交的答案不依赖评论。你们中的一些人可能知道我,这不是我的风格。我尝试了post方法,我注意到我的代码中有两个相同的形式应答器,这就是为什么文件没有上传谢谢
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Then the rest of your code