You are here

function _image_insert in Image 6

Same name and namespace in other branches
  1. 5.2 image.module \_image_insert()
  2. 5 image.module \_image_insert()

Moves temporary (working) images to the final directory and stores relevant information in the files table

2 calls to _image_insert()
image_insert in ./image.module
Implementation of hook_insert().
image_update in ./image.module
Implementation of hook_update().

File

./image.module, line 998

Code

function _image_insert(&$node, $size, $image_path) {
  $original_path = $node->images[IMAGE_ORIGINAL];
  if (file_move($image_path, _image_filename($original_path, $size))) {

    // Update the node to reflect the actual filename, it may have been changed
    // if a file of the same name already existed.
    $node->images[$size] = $image_path;
    $image_info = image_get_info($image_path);
    $file = array(
      'uid' => $node->uid,
      'filename' => $size,
      'filepath' => $image_path,
      'filemime' => $image_info['mime_type'],
      'filesize' => $image_info['file_size'],
      'status' => FILE_STATUS_PERMANENT,
      'timestamp' => time(),
    );
    drupal_write_record('files', $file);
    $image = array(
      'fid' => $file['fid'],
      'nid' => $node->nid,
      'image_size' => $size,
    );
    drupal_write_record('image', $image);
  }
}