Whats my problem with this code:
As you can see, I allow only image files from the $fajl_types array.
But if I select a txt or some other file, it will also be uploaded. I get the error, that incorrect file type, but it will be uploaded anyway.
What am II doing wrong? Should I put a if(count($error) == 0 ) before the move_upload_file function or what?
$error = array();
$fajl_types = array(
                    'png'  => 'image/png',
                    'jpe'  => 'image/jpeg',
                    'jpeg' => 'image/jpeg',
                    'jpg'  => 'image/jpeg',
                    'gif'  => 'image/gif',
                    'bmp'  => 'image/bmp'
                );
if(isset($_POST['send_kapcsolat'])) {
    if(empty($_POST['hiba_nev'])) {
        $error[] = "Name required";
    }
    if(empty($_POST['hiba_email'])){
        $error[] = "Email required.";
    }
    if(isset($_FILES['hiba_file']) && $_FILES["hiba_file"]['size'] != 0 )
    {
        if($_FILES["hiba_file"]["size"] > 5242880 ) { 
            $error[] = "File size is max 5 mb."; 
        }
        $filename = $_FILES["hiba_file"]['name'];
        $ext = pathinfo($filename, PATHINFO_EXTENSION);
        if(!array_key_exists($ext, $fajl_types)) { 
            $error[] = "Incorrect file type"; 
        } 
        $path = "hiba/" . date( "Y-m-d-H:i:s" ) . '-' . rand(1, 9999) . '-' . $_FILES["hiba_file"]['name'];
        if(move_uploaded_file($_FILES["hiba_file"]['tmp_name'], $path ))
        {
            $hiba_file = basename($path);
        }
    }
    else
    {
        $hiba_file = "";
    }
    if(count($error) == 0 )
    {
        $hiba_nev = mysqli_real_escape_string($kapcs, $_POST['hiba_nev']);
        $hiba_email = mysqli_real_escape_string($kapcs, $_POST['hiba_email']);
        $hiba_uzenet = mysqli_real_escape_string($kapcs, $_POST['hiba_uzenet']);
        $hiba_status = (int)0;
        $hiba_date = date("Y-m-d-H:i:s");
        $sql = 
        "
            INSERT INTO hiba
            (
                hiba_nev,
                hiba_email,
                hiba_uzenet,
                hiba_file,
                hiba_status,
                hiba_date
            )
            VALUES
            (
                '".$hiba_nev."',
                '".$hiba_email."',
                '".$hiba_uzenet."',
                '".$hiba_file."',
                '".$hiba_status."',
                '".$hiba_date."'
            )
        ";
        print_r($sql);
    }
}
 
     
     
    