I have this form and I would like to check if the user has selected the file or not.
<form action="upload.php" method="POST" enctype="multipart/form-data" >
<select name="category">
<option value="cat1" name="cat1">Productfotografie</option>
<option value="cat2" name="cat2">Portretten</option>
<option value="cat3" name="cat3">Achitectuur</option>
</select>
<input type="file" name="file_upload">
<input type="submit" name="submit" value="Upload photo">
</form>
I wrote this php code to test it
if (empty($_POST) === false) {
$fileupload = $_POST['file_upload'];
if (empty($fileupload) === true) {
echo "Error no file selected";
} else {
print_r($_FILES);
}
}
But I get "Error without file" even if I do something. Any clue? Sorry I'm really new to PHP.
EDIT: I already tried to replace $ fileupload = $ _FILES ['file_upload'], but it prints an empty error (Array ([file_upload] => Array ([name] => [type] => [tmp_name] => [error] => 4 [size] => 0))) when I do not enter the file?
source
share