You are here

function filefield_file_insert in FileField 5

Same name and namespace in other branches
  1. 5.2 filefield.module \filefield_file_insert()

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 filefield_file_insert()
filefield_field in ./filefield.module
Implementation of hook_field().
filefield_file_update in ./filefield.module
update the file record if necessary

File

./filefield.module, line 93
Defines a file field type.

Code

function filefield_file_insert($node, &$file, $field) {
  $fieldname = $field['field_name'];
  if ($file = file_save_upload((object) $file, file_directory_path() . '/' . $file['filename'])) {
    $file = (array) $file;
    $file['fid'] = db_next_id('{files}_fid');
    db_query('INSERT into {files} (fid, nid, filename, filepath, filemime, filesize)
             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('file upload was unsuccessful.'));
    return FALSE;
  }
}