Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
1  
I'm not sure, but you could do try it from hook_node_presave(). – develkar Sep 26 '12 at 11:11
please tell me the logic behind this, you will save the my head AND the wall :) – magtak Sep 26 '12 at 11:58

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.