Solution:1
You need to save the file as attachment:
// Save to media library
$filename = $_FILES['picture']['name'];
$wp_filetype = wp_check_filetype($filename, null );
$attachment = array(
'guid' => $imageurl,
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name($filename),
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $file );
require_once(ABSPATH . 'wp-admin/includes/image.php');
$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
$res1= wp_update_attachment_metadata( $attach_id, $attach_data );
So basically, your code will look something like this:
add_action( 'show_user_profile', 'fb_add_custom_user_profile_fields' );
add_action( 'edit_user_profile', 'fb_add_custom_user_profile_fields' );
function fb_save_custom_user_profile_fields( $user_id ) {
$uploadUrl = wp_get_upload_dir();
if ( !current_user_can( 'edit_user', $user_id ) )
return FALSE;
$rel = $_POST['relation'];
update_user_meta( $user_id, 'fname_'. $rel, $_POST['fname'] );
update_user_meta( $user_id, 'mname_'.$rel, $_POST['mname'] );
update_user_meta( $user_id, 'lname_'. $rel, $_POST['lname'] );
update_user_meta( $user_id, 'relation', $_POST['relation'] );
update_user_meta( $user_id, 'bod_'. $rel, $_POST['bod'] );
update_user_meta( $user_id, 'education_'.$rel ,$_POST['education'] );
update_user_meta( $user_id, 'occupation_'. $rel, $_POST['occupation'] );
// update_user_meta( $user_id, 'picture_'. $rel, $uploadUrl['url']."/".$_POST['picture'] );
if($_FILES['picture']['name'] != ''){
$uploadedfile = $_FILES['picture'];
$upload_overrides = array( 'test_form' => false );
$movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
$imageurl = "";
if ( $movefile && ! isset( $movefile['error'] ) ) {
$imageurl = $movefile['url'];
// Save to media library
$filename = $_FILES['picture']['name'];
$wp_filetype = wp_check_filetype($filename, null );
$attachment = array(
'guid' => $imageurl,
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name($filename),
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $file );
require_once(ABSPATH . 'wp-admin/includes/image.php');
$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
$res1= wp_update_attachment_metadata( $attach_id, $attach_data );
echo "url : ".$imageurl;
update_user_meta( $user_id, 'picture_'. $rel, $_FILES['picture']['name'] );
} else {
echo $movefile['error'];
}
}
}