Drupal 6 保存节点时,cck图像消失
我保存了一个节点,其中包含由服务填充的图像。我用drupal_write_record写入图像,图像已经出现在节点中。但是,当脚本结束时,我调用一个节点保存图像时,图像再次消失 我的代码:Drupal 6 保存节点时,cck图像消失,drupal-6,imagefield,Drupal 6,Imagefield,我保存了一个节点,其中包含由服务填充的图像。我用drupal_write_record写入图像,图像已经出现在节点中。但是,当脚本结束时,我调用一个节点保存图像时,图像再次消失 我的代码: $file_drupal_path= $filedata['location']; $file = new stdClass(); $file->filename = $filedata['name']; $file->filepath = $file_drupal_path;
$file_drupal_path= $filedata['location'];
$file = new stdClass();
$file->filename = $filedata['name'];
$file->filepath = $file_drupal_path;
$file->filemime = $filedata['mime'];
$file->filesize = filesize($file_drupal_path);
$file->filesource = $filedata['name'];
$file->uid = 1;
$file->status = FILE_STATUS_PERMANENT;
$file->timestamp = time();
$file->list = 1;
// fid is populated by drupal_write_record
drupal_write_record('files', $file);
$imageData = field_file_load($file->fid, TRUE);
return $imageData;
以及保存的节点
function transport_service_save($node) {
$node = (object) ($node);
$node->promote = 1;
node_save(node_submit($node));
return print_r( $node , TRUE );
}
在节点的cck图像字段中,也有未设置值的键。Andreas
有完全相同的问题
使用此处描述的drupal\u execute()
,立即修复了问题:
// Save the node, updated or new
// Get the node object as an array the node_form can use
$values = (array)$node;
// Save the node (this is like pushing the submit button on the node edit form)
drupal_execute('abc_node_form', $values, $node);
资料来源:
但一个合理的警告是:在最初的几轮中,它就像一个符咒,但现在我得到了成吨的错误类型:
warning: call_user_func_array() [function.call-user-func-array]:
First argument is expected to be a valid callback, 'node_form' was given in ...
看不出发生了什么变化。我所做的只是调用保存了几次的页面来测试它
最后(希望如此!)编辑此回复。似乎需要包含包含node_表单的node.module文件,因此添加以下内容:
module_load_include('', 'node', 'node.pages.inc');
在你的代码中(比如在hook_init()
)就可以做到这一点
在这里工作,现在我的节点保存图像时完好无损。Andreas
有完全相同的问题
使用此处描述的drupal\u execute()
,立即修复了问题:
// Save the node, updated or new
// Get the node object as an array the node_form can use
$values = (array)$node;
// Save the node (this is like pushing the submit button on the node edit form)
drupal_execute('abc_node_form', $values, $node);
资料来源:
但一个合理的警告是:在最初的几轮中,它就像一个符咒,但现在我得到了成吨的错误类型:
warning: call_user_func_array() [function.call-user-func-array]:
First argument is expected to be a valid callback, 'node_form' was given in ...
看不出发生了什么变化。我所做的只是调用保存了几次的页面来测试它
最后(希望如此!)编辑此回复。似乎需要包含包含node_表单的node.module文件,因此添加以下内容:
module_load_include('', 'node', 'node.pages.inc');
在你的代码中(比如在hook_init()
)就可以做到这一点
在这里工作,现在我的节点保存图像不变