I have created the "Gallery" content type, and added two fields: "photo," and "document." I then used the following code for uploading a file in the "document" field:
$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.');
}
I am attaching this file to the node using the following code:
$customNode->field_document[$customNode->language][0] = (array)$file;
When I call node_submit()
function, I get the following error:
Integrity constraint violation: 1048 Column 'field_document_display' cannot be null
Does anybody know what I am doing wrong?