I have a custom content type with 2 custom fields: file (file) and list (status).
I can set the value of status by doing:
$node = node_load($n, $r);
$node->field_status[$node->language][0]['value'] = 1;
node_save($node);
I want to create entries for field_file and file_managed (core table) for a file that is ALREADY on the server. I already know the MIME type, size and path of the file.
What is the proper way to achieve this?
I would instantiate the file object manually and use
file_save()to commit it (using an image file as an example):You should then call
file_usage_add()to let Drupal know your module has a vested interest in this file (using thenidfrom your$nodeobject):Finally you can add the file to the node:
Hope that helps