The file access system determines who can do what to which files.

In determining access rights for a file, file_access() first checks whether the user has the "bypass file access" permission. Such users have unrestricted access to all files. user 1 will always pass this check.

Next, all implementations of hook_file_access() will be called. Each implementation may explicitly allow, explicitly deny, or ignore the access request. If at least one module says to deny the request, it will be rejected. If no modules deny the request and at least one says to allow it, the request will be permitted.

There is no access grant system for files.

In file listings, the process above is followed except that hook_file_access() is not called on each file for performance reasons and for proper functioning of the pager system. When adding a filelisting to your module, be sure to use a dynamic query created by db_select() and add a tag of "file_access". This will allow modules dealing with file access to ensure only files to which the user has access are retrieved, through the use of hook_query_TAG_alter().

Note: Even a single module returning FILE_ACCESS_DENY from hook_file_access() will block access to the file. Therefore, implementers should take care to not deny access unless they really intend to. Unless a module wishes to actively deny access it should return FILE_ACCESS_IGNORE (or simply return nothing) to allow other modules to control access.

Stream wrappers that are considered private should implement a 'private' flag equal to TRUE in hook_stream_wrappers().


core/modules/file/file.module, line 2763
Defines a "managed_file" Form API field and a "file" field for Field module.


Namesort descending Location Description
file_access core/modules/file/file.module Determines if a user may perform the given operation on the specified file.
file_entity_access Deprecated core/modules/file/file.module Deprecated wrapper function. Determines if a user may perform the given operation on the specified file.
file_file_access core/modules/file/file.module Implements hook_file_access().
file_get_stream_wrapper core/modules/file/file.module Return a specific stream wrapper's registry information.
file_list_permissions core/modules/file/file.module Helper function to generate standard file permission list for a given type.
file_permissions_get_configured_types core/modules/file/file.module Returns an array of file types that should be managed by permissions.
file_query_entity_field_access_alter core/modules/file/file.module Implements hook_query_TAG_alter().
file_query_file_access_alter core/modules/file/file.module Implements hook_query_TAG_alter().
file_stream_wrappers_alter core/modules/file/file.module Implements hook_stream_wrappers_alter().
file_view_multiple core/modules/file/file.module End of "defgroup file_access".
hook_file_access core/modules/file/file.api.php Control access to a file.
hook_query_file_access_alter core/modules/file/file.api.php Control access to listings of files.
_file_query_file_access_alter core/modules/file/file.module Helper for file entity access functions.