本文介绍了如何使用node_save($ node)创建图像时将图像附加到节点;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在和drupal 7一起工作,并试图通过使用php解析xml,然后在创建具有 node_save($ node)的节点时导入数据。 >

到目前为止,我已经成功地从xml创建了没有任何图像的节点。我想在导入时将图像附加到节点。



我知道drupal 7仍然是alpha 6,但它的好。 node_save($ node)功能与drupal 6几乎相同,但有点不同。



确定这是我的代码图像文件路径存储在一个变量中...任何帮助都会很好...提前提前

  function main($头,$ txt){
$ nodes = array();
$ nodes [0] ['title'] = $ head; // node name
$ nodes [0] ['body'] = $ txt; //节点的身体文本
$ nodes [0] ['teaser'] ='< p>节点< / p>';
$ nodes [0] ['timestamp'] = 1281765101;
$ nodes [0] ['format'] = 2;
make_nodes($ nodes);
}

函数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-> promotion = 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);
}


解决方案

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

  $ uri ='bird / bird_image.jpg; 
$ files = new stdClass();
$ files-> uid =(isset($ local_user-> uid)&∅($ 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数据库


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 node_save($node).

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. node_save($node) 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

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);
}
解决方案

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

这篇关于如何使用node_save($ node)创建图像时将图像附加到节点;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 14:54