function hook_file_insert

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

Drupal\file\File $file: The file that has been added.

2 functions implement hook_file_insert()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

entity_crud_hook_test_file_insert in drupal/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module
Implements hook_file_insert().
file_test_file_insert in drupal/core/modules/file/tests/file_test/file_test.module
Implements hook_file_insert().

File

drupal/core/modules/file/file.api.php, line 83
Hooks for file module.

Code

function hook_file_insert(Drupal\file\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.');
  }
}