未定义的数组键;尝试访问 null 类型值的数组偏移量; foreach() 参数必须是数组|对象类型

Undefined array key; Trying to access array offset on value of type null ; foreach() argument must be of type array|object

我已经尝试了所有方法,有人可以帮助我吗?我收到 3 个错误:foreach()...

PHP: 8.0 MYSQL: 5.1

foreach($_FILES["userfile"]["tmp_name"] as $key=>$tmp_name) {
    $file_name=$_FILES["userfile"]["name"][$key];
    $pasta_dir = "../www/layout/diario_de_obra/upload_img/";
    $diretorio_img = $pasta_dir . $file_name;
    $arquivo = $_FILES["userfile"]['tmp_name'][$key];
    move_uploaded_file($arquivo, $diretorio_img);
    print($file_name." enviado com sucesso!");
}



<div enctype="multipart/form-data">  <!-- action="upload" method="post"  accept=”image/* class="simagem" -->
     <label>Selecione as fotos de hoje aqui:
        <input id="image-file" type="file" name="userfile[]">
        <input id="image-file" type="file" name="userfile[]">
     </label>
</div>

在试用了您的示例之后,我想到了这个

<form action="imageUpload.php" method="post" enctype="multipart/form-data">
    <div>  <!-- action="upload" method="post"  accept=”image/* class="simagem" -->
        <label>Selecione as fotos de hoje aqui:
            <input id="image-file" type="file" name="userfile[]">
            <input id="image-file" type="file" name="userfile[]">
        </label>
    </div>
    <button type="submit">click me</button>
</form>

现在您的 PHP 开始工作了。