File field not getting updated i tried to update file cck field of a content type as below from another node as below. 

&lt;form action="" method="post" id="tfrm" enctype="multipart/form-data"&gt;
    &lt;input id="tf" name="tf" type="file" /&gt;
    &lt;input id="btn" type="submit" value="Submit" name="btn" /&gt;
&lt;/form&gt;
&lt;?php 
if($_POST['btn']){  
$node=node_load(32);

$filename = basename($_FILES['tf']['name']);
$image = file_get_contents($_FILES['tf']['tmp_name']);
$file = file_save_data($image, 'public://' . $filename, FILE_EXISTS_RENAME);
$filesinfo = (object) array(
          'uid' =&gt; 1,
          'uri' =&gt; $file-&gt;uri,
          'filemime' =&gt; file_get_mimetype($file-&gt;uri),
          'status' =&gt; 1,
 ); 
$node-&gt;field_ftest[LANGUAGE_NONE][0]=(array)$filesinfo;
print_r($filesinfo);
  node_save($node);

}
?&gt;


file gets uploaded but results error in updating file field . 

localhost
Error
The website encountered an unexpected error. Please try again later.
Error message

    Notice: Undefined index: fid in file_field_presave() (line 219 of C:\xampp\htdocs\drupal\modules\file\file.field.inc).
    Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController-&gt;load() (line 173 of C:\xampp\htdocs\drupal\includes\entity.inc).
    Notice: Trying to get property of non-object in file_field_presave() (line 220 of C:\xampp\htdocs\drupal\modules\file\file.field.inc).
    Warning: Creating default object from empty value in file_field_presave() (line 221 of C:\xampp\htdocs\drupal\modules\file\file.field.inc).
    Notice: Undefined property: stdClass::$uri in file_save() (line 601 of C:\xampp\htdocs\drupal\includes\file.inc).
    Notice: Undefined index: fid in file_field_update() (line 261 of C:\xampp\htdocs\drupal\modules\file\file.field.inc).
    Notice: Undefined index: fid in file_field_update() (line 287 of C:\xampp\htdocs\drupal\modules\file\file.field.inc).
    Notice: Undefined property: stdClass::$fid in file_usage_add() (line 685 of C:\xampp\htdocs\drupal\includes\file.inc).
    PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'fid' cannot be null: INSERT INTO {file_usage} (fid, module, type, id, count) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4); Array ( [:db_insert_placeholder_0] =&gt; [:db_insert_placeholder_1] =&gt; file [:db_insert_placeholder_2] =&gt; node [:db_insert_placeholder_3] =&gt; 32 [:db_insert_placeholder_4] =&gt; 1 ) in file_usage_add() (line 692 of C:\xampp\htdocs\drupal\includes\file.inc).
You should use Form API to create and manage file uploads and their management. You can do something like this instead:

...
$form['file'] = array(
    '#title' =&gt; t('File'),
    '#type' =&gt; 'managed_file',
    '#description' =&gt; t('File formats: %format. Maximum: %max_size. Resolution %resolution', array('%format' =&gt; 'Jpg, Jpeg, Png, Gif', '%max_size' =&gt; '800 Kb', '%resolution' =&gt; '80x100')),
    '#upload_location' =&gt; 'public://',
);
...


and submit function:

...
$node = node_load(32);
$file_d = $form_state['values']['file'];
$file = file_load($file_d);
$file-&gt;status = FILE_STATUS_PERMANENT;
file_save($file);
file_usage_add($file, 'node', 'TYPE', $file-&gt;fid);
$file_info = image_get_info($file-&gt;uri);

$file_arr = array(
  'fid' =&gt; $file-&gt;fid,
  'alt' =&gt; '',
  'title' =&gt; '',
  'width' =&gt; $file_info['width'],
  'height' =&gt; $file_info['height'],
  'uid' =&gt; $file-&gt;uid,
  'filename' =&gt; $file-&gt;filename,
  'uri' =&gt; $file-&gt;uri,
  'filemime' =&gt; $file-&gt;filemime,
  'filesize' =&gt; $file-&gt;filesize,
  'status' =&gt; 1,
  'timestamp' =&gt; $file-&gt;timestamp,
  'rdf_mapping' =&gt; array(),
);

$node-&gt;field_ftest[LANGUAGE_NONE][0] = $file_arr;
node_save($node);
...