'Undefined array key; Trying to access array offset on value of type null ; foreach() argument must be of type array|object [closed]
I've try everything, can someone help me? Im getting 3 error on: 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>
Solution 1:[1]
After playing around with your example I came up with this
<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>
Now your PHP started working.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Guido Faecke |
