How do I update a node's file field from within a module? I have a file: /tmp/new.zip and I have a node, $node, that has a file field, field_ios_file. Currently, old.zip is the file saved in to the field_ios_file field. I'd like to put /tmp/new.zip there.

What I have now:

$file = file_uri_to_object('/tmp/new.zip');                                                                                
print_r($node-&gt;field_ios_file);
$node-&gt;field_ios_file['und'][0] = $file ;
print_r($node-&gt;field_ios_file);
node_save($node);


the node_save() fails here because $node-&gt;field_ios_file['und'][0] should be an array, not an object. I would imagine there is a function that looks something like field_update($node, $my_field, $data), but I can't find anything like that.
The file field type has a fid column (file ID); you just need to save the file so an ID is populated, and add it to the node like this:

$file = file_uri_to_object('/tmp/new.zip');  
$file-&gt;status = FILE_STATUS_PERMANENT; 
file_save($file);

$node-&gt;field_ios_file[LANGUAGE_NONE][0]['fid'] = $file-&gt;fid;
node_save($node);