You are here

function _cloneimagefield_copy_file in Node clone 5.2

Same name and namespace in other branches
  1. 5 cloneimagefield.module \_cloneimagefield_copy_file()

Copy a specific attached file to a temporary location.

2 calls to _cloneimagefield_copy_file()
cloneimagefield_clone_node_alter in ./cloneimagefield.module
Implementation of hook_clone_node_alter() (a clone.module hook).
cloneimagefield_nodeapi in ./cloneimagefield.module
Implementation of hook_nodeapi().

File

./cloneimagefield.module, line 57

Code

function _cloneimagefield_copy_file(&$node, $key, $delta) {
  $source = $node->{$key}[$delta]['filepath'];

  // Create temporary name/path for duplicated files. On Windows, tempnam()
  // requires an absolute path, so we use realpath().
  $dest = tempnam(realpath(file_directory_temp()), 'tmp_');

  // Copy the file to the temporary location.
  if (file_copy($source, $dest)) {

    // $source now holds the actual filename used for the copy.
    $node->{$key}[$delta]['filepath'] = $source;
    $node->{$key}[$delta]['fid'] = 'upload';
    $node->{$key}[$delta]['nid'] = 0;
  }
  else {

    // Copy failed, remove the file from the list of attachements.
    unset($node->{$key}[$delta]);
  }
}