未定义的索引错误文件$_FILES[';file';][';error';]


Undefined index error file $_FILES['file']['error']

FORM,我正在尝试创建一个博客上传内容和图像

echo '<form action="basics.php" method="POST" enctype="multipart/form-data">';
echo '<b>Upload a Image file</b>';
echo '<input type="file" name="file"/>';
echo "<br>";
echo '<input type="submit" name="submit" value="submit"/>';
echo '</form>'.PHP_EOL;

我在下面的一行中得到了错误,上面写着未定义的索引文件

if(isset($_POST['submit']))
{
    echo $_FILES['file']['error'];
}

请尝试以下操作:

if(isset($_POST['submit']) && isset($_FILES['file']['error']) 
   && !empty($_FILES['file']['error'])) {
    echo $_FILES['file']['error'];
}