I have a problem with $ _FILES PHP to upload a photo Indefinite index fileToUpload this is my code
HTML
<form action="upload.php" method="post" enctype="multipart/form-data">
Seleccionar imagen:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
PHP
//el error aparece en $_FILES["fileToUpload"]["name"]
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "El archivo es una imagen - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "El archivo no es una imagen.";
$uploadOk = 0;
}
}
I have tried in different ways but the result is always the same:
Notice: Undefined index: fileToUpload
When you run var_dump($_FILES)
it returns me:
array (0) {}
but if I run it this way var_dump($_FILES['foto']['name'])
keeps generating the same error.