Deleting images through upload folder, but not deleting from media library

WordPress saves media library in the _posts table – you’ll see post_type of attachment for media library items. You’ll notice a guid value in the row, which is the media items default URL.

While unlink()‘ing your file, you can make the file’s full URL. Then use that full URL in a simple database query ($wpdb) stating WHERE guid = '$thefullURL'. That will return the row, and you’ll be able to get the ID of the media library item.

With ID retrieved you can then delete it with WordPress’s wp_delete_post() (which will delete from library and also a bunch of _postmeta jargon)