how we can upload file on media browser type field programmatically how we can upload file on media browser type field programmatically.
  
  Below are my code:


$temp_attachpath = MYFILEPATH;
        $attachpath = drupal_realpath($temp_attachpath);
        if(file_exists($attachpath)){

            $file = (object) array(
                'uid' =&gt; 1,
                'uri' =&gt; $attachpath,
                'filemime' =&gt; file_get_mimetype($attachpath),
                'status' =&gt; 1,
            );
            // We save the file to the root of the files directory.
            $file = file_copy($file, 'public://');
            $new_node-&gt;field_upload_file[$new_node-&gt;language][0] = (array)$file;
        }else{
            $new_node-&gt;field_upload_file[$new_node-&gt;language][0] = '';
        }
        node_submit($new_node);
        node_save($new_node);
i change my code and its working for me now.

$temp_attachpath = MYFILEPATH;
$attachpath = drupal_realpath($temp_attachpath);
if(file_exists($attachpath)){

    $file = (object) array(
        'uid' =&gt; 1,
        'uri' =&gt; $attachpath,
        'filemime' =&gt; file_get_mimetype($attachpath),
        'status' =&gt; 1,
    );

    $file = file_save_data(file_get_contents($attachpath), 'public://'.basename($attachpath));
    $file-&gt;filename  = basename($attachpath);
    $file-&gt;display = 1;
    $file-&gt;description = "";
    $new_node-&gt;field_upload_file[$new_node-&gt;language][0] = (array)$file;
}else{
    $new_node-&gt;field_upload_file[$new_node-&gt;language][0] = '';
}
node_submit($new_node);
node_save($new_node);