Error while creating a node with file attachment through custom PHP code
replace

$node-&gt;field_file[$node-&gt;language][0]['value'] = (array)$file;

with

$node-&gt;field_file[$node-&gt;language][] = (array)$file;

Also, add $node-&gt;validated = TRUE; before node_save($node);