Я пытаюсь загрузить изображение. Я включил форму с другой страницы (inc / pages / addRecipe2.php), и форма загружается нормально, и я запускаю код для формы на той же странице (addRecipe /? Token = ...), когда я пытаюсьчтобы загрузить файл, он говорит, что существует неопределенный индекс: image
ошибки, которые я получаю:
код формы:
<form enctype="multipart/file-data" method="POST">
<div class="form-group">
<input type="file" class="form-control-file" id="image" name="image">
</div>
<?php
if ($privateRecipe == "public") {
echo "<button type='submit' class='btn btn-primary' style='width: 100%' id='finishRecipe' name='finishRecipe'>Submit recipe for review</button>";
} else {
echo "<button type='submit' class='btn btn-primary' style='width: 100%' id='finishRecipe' name='finishRecipe'>Complete reci</button>";
}
?>
<p class="formMessage1"></p>
</form>
php-код, запустив форму:
if (isset($_POST['finishRecipe'])) {
$recipeId = $_GET['token'];
$image = $_FILES['image'];
$imageName = $_FILES['image']['name'];
$imageTmpName = $_FILES['image']['tmp_name'];
$imageSize = $_FILES['image']['size'];
$imageError = $_FILES['image']['error'];
$imageType = $_FILES['image']['type'];
$fileExt = explode(".", $imageName);
$fileActualExt = strtolower(end($fileExt));
$allowedExt = array('png', 'jpg', 'jpeg');
if (in_array($fileActualExt, $allowedExt)) {
if ($imageError === 0) {
if ($imageSize < 500000) {
$fileNameNew = uniqid('', true) . "." . $fileActualExt;
$fileDestination = "uploads/$fileNameNew";
move_uploaded_file($imageTmpName, $fileDestination);
} else {
echo "The image is too big!";
}
} else {
echo "There was an error with your image!";
}
} else {
echo "File type not allowed!";
}
}
он выдает «тип файла не разрешен», как одно из моих сообщений об ошибках, которые я сделал.
Есть какие-нибудь решения?