Frontend image uploading from edit profile page. (goldenapples)

the problem is in this line :

$attach_id = media_handle_upload( $file_handler, $user_id );

when you use media_handle_upload and provide a second parameter (which in your case you do) the the attachment is associated with a post that has that ID, so basically WordPress thinks your are telling it to save this as an attachment to a post which has the same id as the user and that is way it is saved in the postmeta table.

now the quick fix is to remove $user_id from that line:

$attach_id = media_handle_upload( $file_handler);

next I’m pretty sure that this part does nothing:

if ( !empty( $_POST['authorphoto'] ) )
    update_usermeta( $current_user->id, 'comp_logo', esc_attr($_POST['comp_logo']   ) );  

since input fields with type="file" are not included in $_POST but in $_FILES.

and to display the image on the author template you can use wp_get_attachment_image_src
something like this:

$image_attributes = wp_get_attachment_image_src( get_usermeta($user_id,'_thumbnail_id',true )); // returns an array
echo '<img src="'.$image_attributes[0].'">';

Leave a Comment