1 system.api.php hook_file_insert(File $file)

Respond to a file being added.

This hook is called after a file has been added to the database. The hook doesn't distinguish between files created as a result of a copy or those created by an upload.

Parameters

File $file: The file that has been added.

Related topics

File

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

Code

function hook_file_insert(File $file) {
  // Add a message to the log, if the file is a jpg
  $validate = file_validate_extensions($file, 'jpg');
  if (empty($validate)) {
    watchdog('file', 'A jpg has been added.');
  }
}