прользуясь вот этим материалом http://www.drupal.ru/node/21412
импортирую данные из другой базы
<?php
$MySQLSrcHost
= "localhost";
$MySQLSrcPort = "3306";
$MySQLSrcUsername = "user";
$MySQLSrcPassword = "pass";
$MySQLSrcDatabase = "db";
require
'includes/bootstrap.inc';
require 'modules/node/node.pages.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
if (@($Src_connection=mysql_connect($MySQLSrcHost.":".$MySQLPort,$MySQLSrcUsername,$MySQLSrcPassword)))
{
mysql_query("SET NAMES utf8");
@($Src_database=mysql_select_db($MySQLSrcDatabase));
$result = mysql_query("SELECT id, caption, image, large, is_ext FROM products_materials");
while ($row = mysql_fetch_array($result)){
$node = new stdClass();
$node->title = $row['caption'];
$node->created = time();
$node->type = "upholstery";
node_object_prepare($node);
node->language = 'ru';
if (file_exists ("sites/default/files/".$row["large"])) {
$node->field_texture[0]['filename']['value'] = $row["large"];
$node->field_texture[0]['filepath']['value'] ="sites/default/files/".$row["large"];
$node->field_texture[0]['filesize']['value'] =filesize( "sites/default/files/".$row["image"]);
$node->field_texture[0]['timestamp']['value'] =$node->created;
$node->field_texture[0]['filemime']['value'] ='image/jpeg';
}
elseif (file_exists ("sites/default/files/".$row["image"])) {
$node->field_texture[0]['filename']['value'] = $row["image"];
$node->field_texture[0]['filepath']['value'] ="sites/default/files/".$row["image"];
$node->field_texture[0]['filesize']['value'] =filesize( "sites/default/files/".$row["image"]);
$node->field_texture[0]['timestamp']['value'] =$node->created;
$node->field_texture[0]['filemime']['value'] ='image/jpeg';
}
node_save($node);
}
echo " - Ok ";
}
?>
все бы хорошо
но значения поля filefield остаеться пустым
Комментарии
['value']
добавил к полям для эксперимента
что с ним что без него не удачно
разобрался достаточно было посмотреть документацию filefield на друпал орг
код внутри цикла меняем на примерно такой
<?php
$mime = 'image/jpeg';
$file_drupal_path = "sites/default/files/".$row["large"]; $file = new stdClass();
$file->filename = basename($file_drupal_path);
$file->filepath = $file_drupal_path;
$file->filemime = $mime;
$file->filesize = filesize($file_drupal_path);
$file->uid = 1;
$file->status = FILE_STATUS_PERMANENT;
$file->timestamp = time();
drupal_write_record('files', $file);
$file->fid = db_result(db_query("SELECT fid FROM {files} WHERE filepath = '%s'", $file->filepath));
$node = new stdClass();
$node->title = $row['caption'];
$node->created = time();
$node->type = "upholstery";
node_object_prepare($node);
$node->language = 'ru'; $node->field_texture = array(
array(
'fid' => $file->fid,
'title' => basename($file->filename),
'filename' => $file->filename,
'filepath' => $file->filepath,
'filesize' => $file->filesize,
'mimetype' => $mime,
'description' => basename($file->filename),
'list' => 1,
),
);
node_save($node); ?>