PHP validate form-datam, and insert to SQL, but img is not required
<p>I am making a ticketing system, and when an user upload a ticket, she/he can upload an image, it is recommended, but not required.<br />
When the user send the ticket with an image, validate is work fine, but without image same validate run and got "file-extension error"....<br />
What am i doing wrong?</p>

<blockquote>
  <p>PHP code</p>
</blockquote>

<pre><code>
if ( !isset($_POST['upload_ticket']) ) {
    if ( (empty($_POST['type'])) || ($_POST['categ'] == "") || (empty($_POST['title'])) || (empty($_POST['value'])) ) {
        echo 'Töltse ki a mezőket!</p>';
    } else {
        if ( !empty($_FILES['image']) ) {
            $user_id = $_SESSION[__SITE_ID__]['users']['id'];
            $type = $_POST['type'];
            $categ = $_POST['categ'];
            $title = trim($_POST['title']);
            $title = ucfirst($title);
            $title = htmlspecialchars($title, ENT_QUOTES, "UTF-8");
            $value = trim($_POST['value']);
            $value = ucfirst($value);
            $value = htmlspecialchars($value, ENT_QUOTES, "UTF-8");
            $reg_date = date("Y-m-d H:i:s");

            if ( is_dir('Pictures/' . date('Ymd') . '/') ) {
                $path = 'Pictures/' . date('Ymd') . '/';
            } else {
                $path = mkdir('Pictures/' . date('Ymd') . '/');
            }
            $image_name = $_FILES['image']['name'];
            $image_size = $_FILES['image']['size'];
            $image_tmp = $_FILES['image']['tmp_name'];
            $image_type = $_FILES['image']['type'];
            $image_ext = strtolower(end(explode('.',$image_name)));

            $expensions = array('jpg', 'jpeg', 'png', 'gif');
            $target_file = $path . basename($image_name);
            $imgext = pathinfo($target_file,PATHINFO_EXTENSION);
            if ( in_array($image_ext,$expensions) === false){
                echo 'JPG, JPEG, PNG, GIF megengedett</p>';
            } else if ( $image_size > 2097152 ) {
                echo 'Túl nagy a kép! Max 2 MB</p>';
            } else {
                move_uploaded_file($image_tmp, $target_file);
                $userquery = "INSERT INTO [gyakornok].[dbo].[t_tickets]";
                $userquery .= " (user_id, type, categ_id, status_id, title, value, image, reg_date)";
                $userquery .= " VALUES ('$user_id', '$type', (SELECT id FROM t_status WHERE value='Aktív') , '$categ', '$title', '$value', '$target_file','$reg_date')";
                $userquery = sqlsrv_query($conn, $userquery);
                echo 'Sikeresen elküldte a bejegyzését</p>';
            }   
        } else {
            $user_id = $_SESSION[__SITE_ID__]['users']['id'];
            $type = $_POST['type'];
            $categ = $_POST['categ'];
            $title = trim($_POST['title']);
            $title = ucfirst($title);
            $title = htmlspecialchars($title, ENT_QUOTES, "UTF-8");
            $value = trim($_POST['value']);
            $value = ucfirst($value);
            $value = htmlspecialchars($value, ENT_QUOTES, "UTF-8");
            $reg_date = date("Y-m-d H:i:s");

            $userquery = "INSERT INTO [gyakornok].[dbo].[t_tickets]";
            $userquery .= " (user_id, type, categ_id, status_id, title, value, reg_date)";
            $userquery .= " VALUES ('$user_id', '$type', (SELECT id FROM t_status WHERE value='Aktív') , '$categ', '$title', '$value', '$reg_date')";
            $userquery = sqlsrv_query($conn, $userquery);
            echo 'Sikeresen elküldte a bejegyzését</p>';
        }
    }
}
</code></pre>