views:

31

answers:

2

HI. i am working on a project to import xml contents into drupal 7. i have parsed all the data in php. so far i have been succeded in importing node body and its title. There is no documentation for drupal 7 on how to attach image to the node and tags. i really need help i have spend two days finding it tried a lot. i will be very thank you for someone. please just guide me somewhere

function make_nodes($nodes) {
  $new_node = $nodes[0];
  $node = new stdClass();
  $node->title = $new_node['title'];
  $node->body['und'][0]['value'] = $new_node['body'];
  $node->type = 'article';
  $node->created = $new_node['timestamp'];
  $node->changed = $new_node['timestamp'];
  $node->status = 1;
  $node->promote = 1;
  $node->sticky = 0;
  $node->body['und'][0]['format'] = 1;
  $node->uid = (isset($local_user->uid) && !empty($local_user->uid)?$local_user->uid:1);
  $node->language = 'en';
  $node->timestamp = $new_node['timestamp'];
  $node->revision = 0;
  node_submit($node);
  node_save($node);
}
A: 

You need to add an ImageField to your content type. This was a seperate module in Drupal 6 but moved into core in Drupal 7. There are some import scripts linked on the module page, but the API probably changed in Drupal 7.

You can also check out the Migrate module that provides a framework for importing into Drupal.

Fabian
Hi. There is already ImageField in Article conetent type in drupal 7. thats where i want to save my images linked to the nodes.
Zero Cool
There should be a function for that in the Field API (http://api.drupal.org/api/group/field/7), but that is an area that changed considerably in Drupal 7, the Drupal 6 way will not work anymore.
Fabian
thats true i already tried drupa 6 way...it does not work....i am goign to try somethingsee the body of node is a field as well so i am accessing it likenode->body['und'][0]['value'] = $new_node['body'];thats how to access fields in drupal 7 so it got me thinking that i can also access image field and tags field like maybe similar waynode->field_tags['und'][0]['value'] = 'something';i am not sure but its soemething
Zero Cool
A: 

HI. After reading the documentation for 10 hours i finaly did it...i am including my code here

$uri = 'bird/bird_image.jpg';
$files =  new stdClass();
$files->uid = (isset($local_user->uid) && !empty($local_user->uid)?$local_user->uid:1);
$files->filename = 'bird.jpg';
$files->uri = $uri; 
$files->filemime = file_get_mimetype($uri);
$files->status = 1;
$files->timestamp = $new_node['timestamp'];

file_copy($files);

thats how one can upload file and to the drupal 7 database

Zero Cool

related questions