How to attach an image to a node while creating it with node_save($node);

Hi i am working with drupal 7 and trying to import data from xml by parsing it using php and later on creating nodes with \[code\]node_save($node)\[/code\].So far i have been succeeded to create nodes from xml without any images. I want to attach image to the node while i am importing it. I know drupal 7 is still in alpha 6 but its good. \[code\]node_save($node)\[/code\] function is almost same as in drupal 6 but little bit different.Ok here is my code image file path is stored in a variable...any help would be great..thanks in advance\[code\]function main($head, $txt) { $nodes = array(); $nodes[0]['title'] = $head; // node name $nodes[0]['body'] = $txt; // body text for the node $nodes[0]['teaser'] = '<p>A node</p>'; $nodes[0]['timestamp'] = 1281765101; $nodes[0]['format'] = 2; make_nodes($nodes);}function make_nodes($nodes) { $new_node = $nodes[0]; $node = new stdClass(); $node->type = 'article'; $node->status = 1; $node->uid = 1; $node->title = $new_node['title']; $node->promote = 1; $node->created = $new_node['timestamp']; $node->timestamp = $new_node['timestamp']; $node->changed= $new_node['timestamp']; $node->sticky = 0; $node->language = 'en'; $node->body['und'][0]['format'] = 3; $node->body['und'][0]['summary'] = $new_node['teaser']; $node->body['und'][0]['value'] = $new_node['body']; $node->revision = 0; node_submit($node); node_save($node);}\[/code\]
 
Back
Top