I have a form, in the site's front end, that upon submission creates a new node.
I've been asked to add a file upload form element, so I used FAPIs 'file'.
I overcame some obstacles, and managed to get the file via the $_FILES array since $form_state has no idea that I uploaded a file (weird), and I performed a file_save_upload on it.
The file is now created, in my directory, and in the database as an entry. All is cool.
How on earth do I link it to the node object I am creating? If I try something like this :
$node->field_file_upload[LANGUAGE_NONE][0] = get_object_vars($file);
where $file is the previously saved file, I get this:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'uri':
As if the node_save() that happens one line below tries to recreate the file. I am obviously missing something here, any help?
hook_node_presave()
. – develkar Sep 26 '12 at 11:11