我创建了“图库”内容类型,并添加了两个字段:“照片”和“文档”。然后,我使用以下代码在“文档”字段中上传文件:
$file = file_save_upload('document', array(
'file_validate_extensions' => array('txt doc'), // Validate extensions.
));
// If the file passed validation:
if ($file) {
// Move the file, into the Drupal file system
if ($file = file_move($file, 'public://')) {
$file->status = FILE_STATUS_PERMANENT;
// $file->file_display = 1;
$file = file_save($file);
} else {
$output = t('Failed to write the uploaded file the site\'s file folder.');
}
} else {
$output = t('No file was uploaded.');
}
我使用以下代码将此文件附加到节点:
$customNode->field_document[$customNode->language][0] = (array)$file;
当我调用node_submit()
函数时,出现以下错误:
违反完整性约束:1048字段“ field_document_display”不能为空
有人知道我在做什么错吗?