imagefield_file_insert

Versions
5
imagefield_file_insert($node, &$file, $field)
6
imagefield_file_insert($file)

Insert a file into the database.

Parameters

$node Node object this file is be associated with.

$file File to be inserted, passed by reference since fid should be attached.

▾ 2 functions call imagefield_file_insert()

imagefield_field in contributions/imagefield/imagefield.module
Implementation of hook_field().
imagefield_file_update in contributions/imagefield/imagefield.module
Update the file record if necessary.

Code

contributions/imagefield/imagefield.module, line 239

<?php
function imagefield_file_insert($node, &$file, $field) {
  $fieldname = $field['field_name'];

  // allow tokenized paths.
  if (function_exists('token_replace')) {
    global $user;
    $widget_image_path = token_replace($field['widget']['image_path'], 'user', $user);
  }
  else {
    $widget_image_path = $field['widget']['image_path'];
  }

  $filepath = file_create_path($widget_image_path) .'/'. $file['filename'];

  if (imagefield_check_directory($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)
             VALUES (%d, %d, '%s','%s','%s',%d)",
            $file['fid'], $node->nid, $file['filename'], $file['filepath'], $file['filemime'], $file['filesize']);
    module_invoke_all('imagefield_file', 'save', $file);
    return (array)$file;
  }
  else {
    // Include file name in upload error.
    form_set_error(null, t('Image upload was unsuccessful.'));
    return false;
  }
}
?>