开发者

How to attach image and tag with the node

开发者 https://www.devze.com 2023-01-13 00:42 出处:网络
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 succeeded in importing the node body and its title. There is no documentation for Drup

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 succeeded in importing the node body and its title. There is no documentation for Drupal 7 on how to attach an image to the node and tags. I really need help, as I have spent two days trying to find a solution. I will be very grateful if anyone comes up with a solution. 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);
}


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消