You are here

function _flashnode_insert in Flash Node 5.6

Same name and namespace in other branches
  1. 5.2 flashnode.module \_flashnode_insert()
  2. 5.3 flashnode.module \_flashnode_insert()

Move a temporary file to the flash directory and store information in {files}

1 call to _flashnode_insert()
flashnode_insert in ./flashnode.module
Implementation of hook_insert

File

./flashnode.module, line 906

Code

function _flashnode_insert($nid, $flash, $mime) {

  // Create the destination path and filename from the current name
  $dest = _flashnode_filename(basename($flash));

  // Try to move the flash file to the flash folder, auto renames if it already exists
  if (file_move($flash, $dest)) {

    // Add file data to $node->file
    $file->filename = '_flashnode';
    $file->filepath = _flashnode_filename(basename($flash));
    $file->filemime = $mime;

    // Note use of file_create_path, files are stored with only flash/ prepended so has to be qualified
    $file->filesize = filesize(file_create_path($dest));

    // Create new record in files table
    $fid = db_next_id('{files}_fid');
    db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s', '%s', '%s', '%s')", $fid, $nid, $file->filename, $file->filepath, $file->filemime, $file->filesize);

    // Return the assigned fid
    return $fid;
  }
}