Wordpress attachment upload via PHP
I would comment, but I'm not allowed yet.
1) Are you doing this from the back-end or front-end? You may need a nonce key.
2) On set_post_thumbnail
, does $newId = $post->ID
? That may be why it's not attaching as the featured image.
3) Your filename is not preserving the extension/$photo_name
is not defined in the code. You may be better off with wp_handle_upload.