1 file.module file_access($op, $file = NULL, $account = NULL)

Determines if a user may perform the given operation on the specified file.

Parameters

string $op: The operation to be performed on the file. Possible values are:

  • "view"
  • "download"
  • "update"
  • "delete"
  • "create"

File|string|NULL $file: The file object on which the operation is to be performed, or file type (e.g. 'image') for "create" operation.

User|AnonymousUser $account: Optional, a user object representing the user for whom the operation is to be performed. Determines access for a user other than the current user.

Return value

bool: TRUE if the operation may be performed, FALSE otherwise.

Related topics

File

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

Code

function file_access($op, $file = NULL, $account = NULL) {
  if ($op == 'create') {
    // In some cases a File object, a bundle string, or NULL is provided.
    if ($file == NULL) {
      $bundle = NULL;
    }
    elseif (is_string($file)) {
      $bundle = $file;
    }
    else {
      $bundle = $file->bundle();
    }
    return File::createAccess($bundle, $account);
  }
  elseif ($file instanceof File) {
    return $file->access($op, $account);
  }
  return FALSE;
}