Set featured image from front end side

$my_post = array(
‘post_title’ => ”,
‘post_content’ => ”,
‘post_status’ => ‘publish’,
‘post_type’ => ‘media_center’, // we can set custom post type too
);
$postid = wp_insert_post( $my_post );
$uploadedfile = $_FILES[‘image_file’];
$upload_overrides = array( ‘test_form’ => false );
$movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
if( $movefile ) {
$file = $movefile[‘file’];
$filename = $_FILES[‘image_file’][‘name’];
$url = $movefile[‘url’];
//echo”igex”.$url;
$filetype = wp_check_filetype( basename( $file ), null );
$wp_upload_dir = wp_upload_dir();
$attachment = array(
‘guid’           =>  $wp_upload_dir[‘url’] . ‘/’ . basename( $file ),
‘post_mime_type’ => $filetype[‘type’],
‘post_title’     => preg_replace( ‘/\.[^.]+$/’, ”, basename( $file ) ),
‘post_content’   => ”,
‘post_status’    => ‘inherit’
);
$attach_id = wp_insert_attachment( $attachment, $file, $posts );
require_once( ABSPATH . ‘wp-admin/includes/image.php’ );
$attach_data = wp_generate_attachment_metadata( $attach_id, $file );

wp_update_attachment_metadata( $attach_id, $attach_data );
$c    = set_post_thumbnail( $postid, $attach_id );
}

Time Duration

$old_date = “1991-10-27 18:00:00”;
$current_date = date(‘Y-m-d H:i:s’);

$y1=date(‘Y’, strtotime( $old_date ));
$m1=date(‘m’, strtotime( $old_date ));
$d1=date(‘d’, strtotime( $old_date ));
$h1=date(‘H’, strtotime( $old_date ));
$i1=date(‘i’, strtotime( $old_date ));
$s1=date(‘s’, strtotime( $old_date ));

$y=date(“Y”);
$m=date(“m”);
$d=date(“d”);
$h=date(“H”);
$i=date(“i”);
$s=date(“s”);

$y2 = $y -$y1;
$m2 = $m -$m1;
if($m < $m1){
$y2–;
$m2 += 12;
}
$d2 = $d -$d1;
if($d < $d1){
$m2–;
if($m1==1 || $m1==3 || $m1==5 || $m1==7 || $m1==8 || $m1==10 || $m1==12){$temp_d=31;}
elseif($m1==4 || $m1==6 || $m1==9 || $m1==11){$temp_d=30;}
elseif($m1==4){if($y1%4==0){$temp_d=29;}else{$temp_d=28;}}
$d2 += $temp_d;
}
$h2 = $h -$h1;
if($h < $h1){
$d2–;
$h2 += 24;
}
$i2 = $i -$i1;
if($i < $i1){
$h2–;
$i2 += 60;
}
$s2 = $s -$s1;
if($s < $s1){
$i2–;
$s2 += 60;
}
echo $y2.”-years “.$m2.”-months “.$d2.”-days “.$h2.”-hours “.$i2.”-minuts “.$s2.”-secounds”;