如何将图像和标记附加到节点

时间:2010-08-26 16:03:14

标签: drupal drupal-7

我正在开发一个将XML内容导入Drupal 7的项目。我已经用PHP解析了所有数据。

到目前为止,我已成功导入节点主体及其标题。 Drupal 7没有关于如何将图像附加到节点和标签的文档。我真的需要帮助,因为我花了两天时间试图找到解决方案。如果有人提出解决方案,我将非常感激。请在某处指导我。

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);
}

2 个答案:

答案 0 :(得分:0)

您需要在内容类型中添加ImageField。这是Drupal 6中的一个独立模块,但在Drupal 7中已经移入了核心。在模块页面上链接了一些导入脚本,但是在Drupal 7中API可能已经改变了。

您还可以查看Migrate module,它提供了导入Drupal的框架。

答案 1 :(得分:0)

HI。阅读文档10个小时后,我终于做到了......我在这里包含我的代码

$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);

这就是人们如何上传文件和drupal 7数据库