A space needs to be inserted between the `if` and the opening parenthesis.
Furthermore, this whole `$flag` stuff is pointless - just do this:

    foreach ($queries as $query)
    {
        if ( ! empty($query) && ! $this->db->simple_query($query))
        {
            return FALSE;
        }
    }

    if ($prefs['delete_after_upload'] === TRUE)
    {
        unlink($prefs['filepath']);
    }