嗨我正在使用drupal 7并尝试通过使用php解析它来从xml导入数据,然后使用node_save($node)创建节点.
到目前为止,我已经成功地从xml创建节点而没有任何图像.我想在导入时将图像附加到节点.
我知道drupal 7仍然处于alpha 6但它很好. node_save($node)函数与drupal 6中的函数几乎相同但略有不同.
好的,这是我的代码图像文件路径存储在一个变量…任何帮助将是伟大的..谢谢提前
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.在阅读了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数据库