function hook_file_copy

hook_file_copy($file, $source)

Respond to a file that has been copied.

Parameters

$file: The newly copied file object.

$source: The original file before the copy.

See also

file_copy()

Related topics

File

modules/system/system.api.php, line 2928
Hooks provided by Drupal core and the System module.

Code

function hook_file_copy($file, $source) {
  $file_user = user_load($file->uid);
  // Make sure that the file name starts with the owner's user name.
  if (strpos($file->filename, $file_user->name) !== 0) {
    $file->filename = $file_user->name . '_' . $file->filename;
    $file->save();

    watchdog('file', t('Copied file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->filename)));
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_file_copy/7.x