File interface

  1. 7.x drupal/includes/ file
  2. 5.x drupal/includes/ file
  3. 6.x drupal/includes/ file
  4. 8.x drupal/core/includes/ file

Common file handling functions.

Fields on the file entity:

  • fid: File ID
  • uid: The {users}.uid of the user who is associated with the file.
  • filename: Name of the file with no path components. This may differ from the basename of the filepath if the file is renamed to avoid overwriting an existing file.
  • uri: URI of the file.
  • filemime: The file's MIME type.
  • filesize: The size of the file in bytes.
  • status: A bitmapped field indicating the status of the file. The first 8 bits are reserved for Drupal core. The least significant bit indicates temporary (0) or permanent (1). Temporary files will be removed during cron runs if they are older than the configuration value "system.file.temporary_maximum_age", and if clean-up is enabled. Permanent files will not be removed.
  • timestamp: UNIX timestamp for the date the file was added to the database.


Namesort descending Location Description
drupal_basename drupal/core/includes/ Gets the filename from a given path.
drupal_chmod drupal/core/includes/ Sets the permissions on a file or directory.
drupal_dirname drupal/core/includes/ Gets the name of the directory from a given path.
drupal_mkdir drupal/core/includes/ Creates a directory, optionally creating missing components in the path to the directory.
drupal_move_uploaded_file drupal/core/includes/ Moves an uploaded file to a new location.
drupal_realpath drupal/core/includes/ Resolves the absolute filepath of a local URI or filepath.
drupal_rmdir drupal/core/includes/ Removes a directory.
drupal_tempnam drupal/core/includes/ Creates a file with a unique filename in the specified directory.
drupal_unlink drupal/core/includes/ Deletes a file.
file_build_uri drupal/core/includes/ Constructs a URI to Drupal's default files location given a relative path.
file_create_filename drupal/core/includes/ Creates a full file path from a directory and filename.
file_create_url drupal/core/includes/ Creates a web-accessible URL for a stream to an external or local file.
file_default_scheme drupal/core/includes/ Gets the default file stream implementation.
file_delete drupal/core/includes/ Deletes a file and its database record.
file_delete_multiple drupal/core/includes/ Deletes files.
file_destination drupal/core/includes/ Determines the destination path for a file.
file_directory_os_temp drupal/core/includes/ Discovers a writable system-appropriate temporary directory.
file_directory_temp drupal/core/includes/ Gets and sets the path of the configured temporary directory.
file_ensure_htaccess drupal/core/includes/ Creates a .htaccess file in each Drupal files directory if it is missing.
file_get_file_references drupal/core/modules/file/file.module Retrieves a list of references to a file.
file_get_mimetype Deprecated drupal/core/includes/ Determines an Internet Media Type or MIME type from a filename.
file_get_stream_wrappers drupal/core/includes/ Provides Drupal stream wrapper registry.
file_htaccess_lines drupal/core/includes/ Returns the standard .htaccess lines that Drupal writes to file directories.
file_munge_filename drupal/core/includes/ Modifies a filename as needed for security purposes.
file_prepare_directory drupal/core/includes/ Checks that the directory exists and is writable.
file_save_htaccess drupal/core/includes/ Creates a .htaccess file in the given directory.
file_scan_directory drupal/core/includes/ Finds all files that match a given mask in a given directory.
file_stream_wrapper_get_class drupal/core/includes/ Returns the stream wrapper class name for a given scheme.
file_stream_wrapper_get_instance_by_scheme drupal/core/includes/ Returns a reference to the stream wrapper class responsible for a scheme.
file_stream_wrapper_get_instance_by_uri drupal/core/includes/ Returns a reference to the stream wrapper class responsible for a given URI.
file_stream_wrapper_uri_normalize drupal/core/includes/ Normalizes a URI by making it syntactically correct.
file_stream_wrapper_valid_scheme drupal/core/includes/ Checks that the scheme of a stream URI is valid.
file_unmanaged_copy drupal/core/includes/ Copies a file to a new location without invoking the file API.
file_unmanaged_delete drupal/core/includes/ Deletes a file without database changes or hook invocations.
file_unmanaged_delete_recursive drupal/core/includes/ Deletes all files and directories in the specified filepath recursively.
file_unmanaged_move drupal/core/includes/ Moves a file to a new location without database changes or hook invocation.
file_unmanaged_save_data drupal/core/includes/ Saves a file to the specified destination without invoking file API.
file_unmunge_filename drupal/core/includes/ Undoes the effect of file_munge_filename().
file_upload_max_size drupal/core/includes/ Determines the maximum file upload size by querying the PHP settings.
file_uri_scheme drupal/core/includes/ Returns the scheme of a URI (e.g. a stream).
file_uri_target drupal/core/includes/ Returns the part of a URI after the schema.
file_url_transform_relative drupal/core/includes/ Transforms an absolute URL of a local file to a relative URL.
file_valid_uri drupal/core/includes/ Determines whether the URI has a valid scheme for file API operations.
_drupal_mkdir_call drupal/core/includes/ Helper function. Ensures we don't pass a NULL as a context resource to mkdir().


Namesort descending Location Description
FILE_CREATE_DIRECTORY drupal/core/includes/ Flag used by file_prepare_directory() -- create directory if not present.
FILE_EXISTS_ERROR drupal/core/includes/ Flag for dealing with existing files: Do nothing and return FALSE.
FILE_EXISTS_RENAME drupal/core/includes/ Flag for dealing with existing files: Appends number until name is unique.
FILE_EXISTS_REPLACE drupal/core/includes/ Flag for dealing with existing files: Replace the existing file.
FILE_MODIFY_PERMISSIONS drupal/core/includes/ Flag used by file_prepare_directory() -- file permissions may be changed.
FILE_STATUS_PERMANENT drupal/core/includes/ Indicates that the file is permanent and should not be deleted.


drupal/core/includes/, line 97
API for handling file uploads and server file management.