File interface

Common file handling functions.

Fields on the file object:

  • 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 older than DRUPAL_MAXIMUM_TEMP_FILE_AGE will be removed during cron runs.
  • timestamp: UNIX timestamp for the date the file was added to the database.

Functions & methods

NameLocationDescription
drupal_basenameincludes/file.incGets the filename from a given path.
drupal_chmodincludes/file.incSets the permissions on a file or directory.
drupal_dirnameincludes/file.incGets the name of the directory from a given path.
drupal_mkdirincludes/file.incCreates a directory using Drupal's default mode.
drupal_move_uploaded_fileincludes/file.incMoves an uploaded file to a new location.
drupal_realpathincludes/file.incReturns the absolute local filesystem path of a stream URI.
drupal_rmdirincludes/file.incRemoves a directory.
drupal_tempnamincludes/file.incCreates a file with a unique filename in the specified directory.
drupal_unlinkincludes/file.incDeletes a file.
file_build_uriincludes/file.incConstructs a URI to Drupal's default files location given a relative path.
file_copyincludes/file.incCopies a file to a new location and adds a file record to the database.
file_create_filenameincludes/file.incCreates a full file path from a directory and filename.
file_create_htaccessincludes/file.incCreates a .htaccess file in the given directory.
file_create_urlincludes/file.incCreates a web-accessible URL for a stream to an external or local file.
file_default_schemeincludes/file.incGets the default file stream implementation.
file_deleteincludes/file.incDeletes a file and its database record.
file_destinationincludes/file.incDetermines the destination path for a file.
file_directory_tempincludes/file.incGets the path of system-appropriate temporary directory.
file_downloadincludes/file.incMenu handler for private file transfers.
file_ensure_htaccessincludes/file.incCreates a .htaccess file in each Drupal files directory if it is missing.
file_get_content_headersincludes/file.incExamines a file object and returns appropriate content headers for download.
file_get_mimetypeincludes/file.incDetermines an Internet Media Type or MIME type from a filename.
file_get_stream_wrappersincludes/file.incProvides Drupal stream wrapper registry.
file_loadincludes/file.incLoads a single file object from the database.
file_load_multipleincludes/file.incLoads file objects from the database.
file_moveincludes/file.incMoves a file to a new location and update the file's database entry.
file_munge_filenameincludes/file.incModifies a filename as needed for security purposes.
file_prepare_directoryincludes/file.incChecks that the directory exists and is writable.
file_saveincludes/file.incSaves a file object to the database.
file_save_dataincludes/file.incSaves a file to the specified destination and creates a database entry.
file_save_uploadincludes/file.incSaves a file upload to a new location.
file_scan_directoryincludes/file.incFinds all files that match a given mask in a given directory.
file_space_usedincludes/file.incDetermines total disk space used by a single user or the whole filesystem.
file_stream_wrapper_get_classincludes/file.incReturns the stream wrapper class name for a given scheme.
file_stream_wrapper_get_instance_by_schemeincludes/file.incReturns a reference to the stream wrapper class responsible for a scheme.
file_stream_wrapper_get_instance_by_uriincludes/file.incReturns a reference to the stream wrapper class responsible for a given URI.
file_stream_wrapper_uri_normalizeincludes/file.incNormalizes a URI by making it syntactically correct.
file_stream_wrapper_valid_schemeincludes/file.incChecks that the scheme of a stream URI is valid.
file_transferincludes/file.incTransfers a file to the client using HTTP.
file_unmanaged_copyincludes/file.incCopies a file to a new location without invoking the file API.
file_unmanaged_deleteincludes/file.incDeletes a file without database changes or hook invocations.
file_unmanaged_delete_recursiveincludes/file.incDeletes all files and directories in the specified filepath recursively.
file_unmanaged_moveincludes/file.incMoves a file to a new location without database changes or hook invocation.
file_unmanaged_save_dataincludes/file.incSaves a string to the specified destination without invoking file API.
file_unmunge_filenameincludes/file.incUndoes the effect of file_munge_filename().
file_upload_max_sizeincludes/file.incDetermines the maximum file upload size by querying the PHP settings.
file_uri_schemeincludes/file.incReturns the scheme of a URI (e.g. a stream).
file_uri_targetincludes/file.incReturns the part of a URI after the schema.
file_usage_addincludes/file.incRecords that a module is using a file.
file_usage_deleteincludes/file.incRemoves a record to indicate that a module is no longer using a file.
file_usage_listincludes/file.incDetermines where a file is used.
file_validateincludes/file.incChecks that a file meets the criteria specified by the validators.
file_validate_extensionsincludes/file.incChecks that the filename ends with an allowed extension.
file_validate_image_resolutionincludes/file.incVerifies that image dimensions are within the specified maximum and minimum.
file_validate_is_imageincludes/file.incChecks that the file is recognized by image_get_info() as an image.
file_validate_name_lengthincludes/file.incChecks for files with names longer than we can store in the database.
file_validate_sizeincludes/file.incChecks that the file's size is below certain limits.
file_valid_uriincludes/file.incDetermines whether the URI has a valid scheme for file API operations.

Constants

NameLocationDescription
FILE_CREATE_DIRECTORYincludes/file.incFlag used by file_prepare_directory() -- create directory if not present.
FILE_EXISTS_ERRORincludes/file.incFlag for dealing with existing files: Do nothing and return FALSE.
FILE_EXISTS_RENAMEincludes/file.incFlag for dealing with existing files: Appends number until name is unique.
FILE_EXISTS_REPLACEincludes/file.incFlag for dealing with existing files: Replace the existing file.
FILE_MODIFY_PERMISSIONSincludes/file.incFlag used by file_prepare_directory() -- file permissions may be changed.
FILE_STATUS_PERMANENTincludes/file.incIndicates that the file is permanent and should not be deleted.

File

includes/file.inc, line 17
API for handling file uploads and server file management.