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

Kamal Palei palei.kamal at gmail.com
Wed Oct 10 05:36:27 UTC 2012


On further debugging it looks node_save is not working as expected.

node-save() basicall looks as below

transaction();

try
{
//do node save related steps
rollback();
}catch(Exception)


Looks during node_save execution, finaly it comes to exception block.

Is it a bug or I am doing some mistake before calling node_save().

Regards
kamal


On Wed, Oct 10, 2012 at 7:38 AM, Kamal Palei <palei.kamal at gmail.com> wrote:

> 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/4d6f0bfa/attachment.html 


More information about the support mailing list