Hey @ulinn
Sorry I just took another look at your code and found the issue – in update_post_meta, you are setting the value of the _thumbnail_id meta to the variable $downloadcenter_id which has not been defined.
Update that line to the following –
update_post_meta($post_id, '_thumbnail_id', $attachment_id);
Test and let me know if you still have any issues with it!