i tried to update file cck field of a content type as below from another node as below.
<form action="" method="post" id="tfrm" enctype="multipart/form-data">
<input id="tf" name="tf" type="file" />
<input id="btn" type="submit" value="Submit" name="btn" />
</form>
<?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' => 1,
'uri' => $file->uri,
'filemime' => file_get_mimetype($file->uri),
'status' => 1,
);
$node->field_ftest[LANGUAGE_NONE][0]=(array)$filesinfo;
print_r($filesinfo);
node_save($node);
}
?>
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->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] => [:db_insert_placeholder_1] => file [:db_insert_placeholder_2] => node [:db_insert_placeholder_3] => 32 [:db_insert_placeholder_4] => 1 ) in file_usage_add() (line 692 of C:\xampp\htdocs\drupal\includes\file.inc).