You are here

function emthumb_file_insert in Embedded Media 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 emthumb_file_insert()
emthumb_emfield_field_extra in contrib/emthumb/emthumb.module
emthumb_file_update in contrib/emthumb/emthumb.module
update the file record if necessary

File

contrib/emthumb/emthumb.module, line 58

Code

function emthumb_file_insert($node, &$file, $field) {
  $fieldname = $field['field_name'];
  $filepath = file_create_path($field['widget']['emimport_image_path']) . '/' . $file['filename'];
  if (emthumb_check_directory($field['widget']['emimport_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('Thumbnail upload was unsuccessful.'));
    return FALSE;
  }
}