im using the following code to upload an array of files when a node gets saved.
function mymodule_node_update($node){
$result = $query;
foreach ($result as $record) {
$url = ($record['src']);
$name_arr = explode('/', $url );
$filename = end($name_arr);
$filepath = system_retrieve_file($url, 'public://my_files/');
$file = new StdClass();
$file->uid = 1;
$file->uri = $filepath;
$file->filename = $filename;
$file->filemime = file_get_mimetype($file->uri);
$file->status = 1;
$dest = file_default_scheme() . '://'.$filename;
$file = file_copy($file, $dest);
$file->display = 1;
$file->description = "";
}
}
This uploads the files to my public directory, and creates an entry into files_managed in my database.
But now how do I link those files to a filefield on the node im updating? I've tried variations of
$node->field_file = (array)$file;
but nothing is working.
Thanks for any help