[support] Is it possible to attach an existing file to a newly created node - ??

Kamal Palei palei.kamal at gmail.com
Wed Oct 10 02:08:53 UTC 2012


Dear All
I have spent quite a lot of time to attach an existing file at server side
to a newly created node.
I googled quite a bit, almost everywhere the examples are there for file
uplaod / save and then attach to a node.
Did not get any documentation thats says how to attach an existing file to
a newly created node .

At a high level, my code is as below.

$node = new stdClass();
$node->type = resume' ;  // a new content type created
node_object_prepare($node);
$node->title = My title';
$node->language = 'en';
$node->uid = 1;
$file_obj = file_load($fid);
$node->field_resume[$node->language][0] = (array)$file_obj; //field_resume
is the machine name for file field
node_save($node);


Can somebody please let me know what I am missing here?
The new node is created, with no attachment.
How can I get the file to attached to node.

Regards
kamal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20121010/5408ec08/attachment-0001.html 


More information about the support mailing list