function linkimagefield_file_insert in Link Image Field 5
insert a file into the database.
Parameters
$node: node object file will be associated with.
$file: file to be inserted, passed by reference since fid should be attached.
2 calls to linkimagefield_file_insert()
- linkimagefield_field in ./
linkimagefield.module - Implementation of hook_field().
- linkimagefield_file_update in ./
linkimagefield.module - update the file record if necessary
File
- ./
linkimagefield.module, line 100 - Defines an link image field type. linkimagefield uses content.module to store the fid, and the drupal files table to store the actual file data.
Code
function linkimagefield_file_insert($node, &$file, $field) {
$fieldname = $field['field_name'];
$filepath = file_create_path($field['widget']['image_path']) . '/' . $file['filename'];
if (linkimagefield_check_directory($field['widget']['image_path']) && ($file = file_save_upload((object) $file, $filepath))) {
$file = (array) $file;
$file['fid'] = db_next_id('{files}_fid');
db_query("INSERT into {files} (fid, nid, filename, filepath, filemime, filesize)\n VALUES (%d, %d, '%s','%s','%s',%d)", $file['fid'], $node->nid, $file['filename'], $file['filepath'], $file['filemime'], $file['filesize']);
return (array) $file;
}
else {
// Include file name in upload error.
form_set_error(NULL, t('Image upload was unsuccessful.'));
return FALSE;
}
}