Drupal 8  8.0.2
File interface

Functions

 file_uri_scheme ($uri)
 
 file_stream_wrapper_valid_scheme ($scheme)
 
 file_uri_target ($uri)
 
 file_default_scheme ()
 
 file_stream_wrapper_uri_normalize ($uri)
 
 file_create_url ($uri)
 
 file_url_transform_relative ($file_url)
 
 file_prepare_directory (&$directory, $options=FILE_MODIFY_PERMISSIONS)
 
 file_ensure_htaccess ()
 
 file_save_htaccess ($directory, $private=TRUE, $force_overwrite=FALSE)
 
 file_htaccess_lines ($private=TRUE)
 
 file_valid_uri ($uri)
 
 file_unmanaged_copy ($source, $destination=NULL, $replace=FILE_EXISTS_RENAME)
 
 file_build_uri ($path)
 
 file_destination ($destination, $replace)
 
 file_unmanaged_move ($source, $destination=NULL, $replace=FILE_EXISTS_RENAME)
 
 file_munge_filename ($filename, $extensions, $alerts=TRUE)
 
 file_unmunge_filename ($filename)
 
 file_create_filename ($basename, $directory)
 
 file_delete ($fid)
 
 file_delete_multiple (array $fids)
 
 file_unmanaged_delete ($path)
 
 file_unmanaged_delete_recursive ($path, $callback=NULL)
 
 drupal_move_uploaded_file ($filename, $uri)
 
 file_unmanaged_save_data ($data, $destination=NULL, $replace=FILE_EXISTS_RENAME)
 
 file_scan_directory ($dir, $mask, $options=array(), $depth=0)
 
 file_upload_max_size ()
 
 drupal_chmod ($uri, $mode=NULL)
 
 drupal_unlink ($uri, $context=NULL)
 
 drupal_realpath ($uri)
 
 drupal_dirname ($uri)
 
 drupal_basename ($uri, $suffix=NULL)
 
 drupal_mkdir ($uri, $mode=NULL, $recursive=FALSE, $context=NULL)
 
 drupal_rmdir ($uri, $context=NULL)
 
 drupal_tempnam ($directory, $prefix)
 
 file_directory_temp ()
 
 file_directory_os_temp ()
 

Variables

const FILE_CREATE_DIRECTORY = 1
 
const FILE_MODIFY_PERMISSIONS = 2
 
const FILE_EXISTS_RENAME = 0
 
const FILE_EXISTS_REPLACE = 1
 
const FILE_EXISTS_ERROR = 2
 
const FILE_STATUS_PERMANENT = 1
 

Detailed Description

Common file handling functions.

Fields on the file entity:

Function Documentation

drupal_chmod (   $uri,
  $mode = NULL 
)

Sets the permissions on a file or directory.

Deprecated:
in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0. Use ::chmod().

Referenced by Image\chmod(), file_prepare_directory(), file_save_htaccess(), file_unmanaged_copy(), DirectoryTest\testFileCheckDirectoryHandling(), and FileStorage\write().

Here is the caller graph for this function:

drupal_dirname (   $uri)

Gets the name of the directory from a given path.

Deprecated:
in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0. Use ::dirname().

Referenced by ImageStyle\createDerivative(), file_destination(), file_unmanaged_copy(), FileTokenReplaceTest\testFileTokenReplacement(), and UnmanagedCopyTest\testOverwriteSelf().

Here is the caller graph for this function:

drupal_mkdir (   $uri,
  $mode = NULL,
  $recursive = FALSE,
  $context = NULL 
)

Creates a directory, optionally creating missing components in the path to the directory.

Deprecated:
in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0. Use ::mkdir().

Referenced by Connection\createDatabase(), FileTestBase\createDirectory(), file_prepare_directory(), LocalStream\mkdir(), SaveUploadTest\testDrupalMovingUploadedFileError(), DirectoryTest\testFileCheckLocalDirectoryHandling(), RetrieveFileTest\testFileRetrieving(), and ReadOnlyStreamWrapperTest\testReadOnlyBehavior().

Here is the caller graph for this function:

drupal_move_uploaded_file (   $filename,
  $uri 
)

Moves an uploaded file to a new location.

Deprecated:
in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0. Use ::moveUploadedFile().
drupal_realpath (   $uri)

Resolves the absolute filepath of a local URI or filepath.

Deprecated:
in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0. Use ::realpath().

Referenced by ColorTest\_testColor(), FileTransfer\checkPath(), file_unmanaged_copy(), ImageItem\generateSampleValue(), LocaleUpdateBase\makePoFile(), ImageFieldTestBase\previewNodeImage(), FileFieldTestBase\replaceNodeFile(), GDToolkit\save(), UserPictureTest\saveUserPicture(), UpdateReady\submitForm(), UpdateManagerInstall\submitForm(), CommentPreviewTest\testCommentPreview(), ImageFieldDefaultImagesTest\testDefaultImages(), FileFieldDisplayTest\testDescToggle(), SaveUploadTest\testDrupalMovingUploadedFileError(), SaveUploadTest\testExistingError(), SaveUploadTest\testExistingRename(), SaveUploadTest\testExistingReplace(), DirectoryTest\testFileCheckLocalDirectoryHandling(), FileListingTest\testFileListingPages(), EntityReferenceFileUploadTest\testFileUpload(), StateValuesCleanAdvancedTest\testFormStateValuesCleanAdvanced(), SaveUploadTest\testHandleDangerousFile(), SaveUploadTest\testHandleExtension(), SaveUploadTest\testHandleFileMunge(), ConfigImportUploadTest\testImport(), FileManagedFileElementTest\testManagedFile(), FileManagedFileElementTest\testManagedFileRemoved(), FileFieldWidgetTest\testMultiValuedWidget(), SaveUploadTest\testNormal(), PagePreviewTest\testPagePreview(), FileFieldWidgetTest\testPrivateFileComment(), PrivateFileOnTranslatedEntityTest\testPrivateLanguageFile(), TextFieldTest\testRequiredLongTextWithFileUpload(), ThemeTest\testThemeSettings(), LocaleUpdateCronTest\testUpdateCron(), UpdateDeleteFileIfStaleTest\testUpdateDeleteFileIfStale(), UserPasswordResetTest\testUserPasswordReset(), FileFieldWidgetTest\testWidgetValidation(), ImageFieldTestBase\uploadNodeImage(), and ThemeSettingsForm\validatePath().

Here is the caller graph for this function:

drupal_rmdir (   $uri,
  $context = NULL 
)

Removes a directory.

Deprecated:
in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0. Use ::rmdir().

Referenced by FileStorage\deleteAll(), file_unmanaged_delete_recursive(), Local\removeDirectoryJailed(), LocalStream\rmdir(), and ReadOnlyStreamWrapperTest\testReadOnlyBehavior().

Here is the caller graph for this function:

drupal_tempnam (   $directory,
  $prefix 
)

Creates a file with a unique filename in the specified directory.

Deprecated:
in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0. Use ::tempnam().

Referenced by Tasks\connect(), file_unmanaged_save_data(), ImageItem\generateSampleValue(), and GDToolkit\save().

Here is the caller graph for this function:

file_build_uri (   $path)

Constructs a URI to Drupal's default files location given a relative path.

References file_default_scheme(), and file_stream_wrapper_uri_normalize().

Referenced by ImageStyle\buildUrl(), file_unmanaged_copy(), and StreamWrapperTest\testUriFunctions().

Here is the call graph for this function:

Here is the caller graph for this function:

file_create_filename (   $basename,
  $directory 
)

Creates a full file path from a directory and filename.

If a file with the specified name already exists, an alternative will be used.

Parameters
$basenameString filename
$directoryString containing the directory or parent URI.
Returns
File path consisting of $directory and a unique filename based off of $basename.

Referenced by file_destination(), DirectoryTest\testFileCreateNewFilepath(), and DownloadTest\testFileCreateUrl().

Here is the caller graph for this function:

file_create_url (   $uri)

Creates a web-accessible URL for a stream to an external or local file.

Compatibility: normal paths and stream wrappers.

There are two kinds of local files:

  • "managed files", i.e. those stored by a Drupal-compatible stream wrapper. These are files that have either been uploaded by users or were generated automatically (for example through CSS aggregation).
  • "shipped files", i.e. those outside of the files directory, which ship as part of Drupal core or contributed modules or themes.
Parameters
string$uriThe URI to a file for which we need an external URL, or the path to a shipped file.
Returns
string A string containing a URL that may be used to access the file. If the provided string already contains a preceding 'http', 'https', or '/', nothing is done and the same string is returned. If a stream wrapper could not be found to generate an external URL, then FALSE is returned.
See Also
https://www.drupal.org/node/515192
file_url_transform_relative()

References Drupal\moduleHandler(), and Drupal\service().

Referenced by ColorTest\_testColor(), ImageStyle\buildUrl(), ImageStylesPathAndUrlTest\doImageStyleUrlAndPathTests(), DownloadTest\doPrivateFileTransferTest(), SimpleTestTest\getTestResults(), ImageButton\preRenderButton(), CssOptimizerUnitTest\providerTestOptimize(), CssCollectionRendererUnitTest\providerTestRender(), JsCollectionRenderer\render(), CssCollectionRenderer\render(), File\renderLink(), CssOptimizer\rewriteFileURI(), TestBase\run(), EditorImageDialog\submitForm(), ImportOpmlTest\submitImportForm(), AttachedAssetsTest\testAddFiles(), AttachedAssetsTest\testAddJsFileWithQueryString(), AttachedAssetsTest\testAggregatedAttributes(), AttachedAssetsTest\testAttributes(), AttachedAssetsTest\testBrowserConditionalComments(), CKEditorTest\testBuildContentsCssJSSetting(), DownloadTest\testFileCreateUrl(), FileDenormalizeTest\testFileDenormalize(), FileItemTest\testFileItem(), FileListingTest\testFileListingPages(), RetrieveFileTest\testFileRetrieving(), FileEntityFormatterTest\testFormatterFileLink(), FileEntityFormatterTest\testFormatterFileUri(), CKEditorTest\testGetJSSettings(), AttachedAssetsTest\testHeaderHTML(), FileFieldAttributesTest\testNodeTeaser(), FileNormalizeTest\testNormalize(), DownloadTest\testPublicFileTransfer(), UrlRewritingTest\testPublicManagedFileURL(), UrlRewritingTest\testRelativeFileURL(), UrlRewritingTest\testShippedFileURL(), FileFieldWidgetTest\testSingleValuedWidget(), ImageTest\testThemeImageWithSrc(), ImageTest\testThemeImageWithSrcsetMultiplier(), ImageTest\testThemeImageWithSrcsetWidth(), ThemeTest\testThemeSettings(), EngineTwigTest\testTwigFileUrls(), StreamWrapperTest\testUriFunctions(), File\url(), ImportOpmlTest\validateImportFormFields(), UrlPlainFormatter\viewElements(), RSSEnclosureFormatter\viewElements(), BaseFieldFileFormatterBase\viewElements(), ImageFormatter\viewElements(), ResponsiveImageFormatter\viewElements(), and FileUriFormatter\viewValue().

Here is the call graph for this function:

file_delete (   $fid)

Deletes a file and its database record.

Instead of directly deleting a file, it is strongly recommended to delete file usages instead. That will automatically mark the file as temporary and remove it during cleanup.

Parameters
$fidThe file id.
See Also
file_unmanaged_delete()
::delete()

References file_delete_multiple().

Here is the call graph for this function:

file_delete_multiple ( array  $fids)

Deletes files.

Instead of directly deleting a file, it is strongly recommended to delete file usages instead. That will automatically mark the file as temporary and remove it during cleanup.

Parameters
$fidThe file id.
See Also
file_unmanaged_delete()
::delete()

Referenced by file_delete().

Here is the caller graph for this function:

file_destination (   $destination,
  $replace 
)

Determines the destination path for a file.

Parameters
$destinationA string specifying the desired final URI or filepath.
$replaceReplace behavior when the destination file already exists.
  • FILE_EXISTS_REPLACE - Replace the existing file.
  • FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique.
  • FILE_EXISTS_ERROR - Do nothing and return FALSE.
Returns
The destination filepath, or FALSE if the file already exists and FILE_EXISTS_ERROR is specified.

References drupal_basename(), drupal_dirname(), file_create_filename(), FILE_EXISTS_ERROR, FILE_EXISTS_RENAME, and FILE_EXISTS_REPLACE.

Referenced by file_unmanaged_copy(), DirectoryTest\testFileDestination(), and EntityFile\writeFile().

Here is the call graph for this function:

Here is the caller graph for this function:

file_directory_os_temp ( )

Discovers a writable system-appropriate temporary directory.

Returns
mixed A string containing the path to the temporary directory.

Referenced by file_directory_temp().

Here is the caller graph for this function:

file_directory_temp ( )

Gets and sets the path of the configured temporary directory.

Returns
mixed|null A string containing the path to the temporary directory.

References Drupal\config(), Drupal\configFactory(), and file_directory_os_temp().

Referenced by ConfigController\downloadExport(), TemporaryStream\getDirectoryPath(), ConfigExportUITest\testExport(), and DirectoryTest\testFileDirectoryTemp().

Here is the call graph for this function:

Here is the caller graph for this function:

file_ensure_htaccess ( )

Creates a .htaccess file in each Drupal files directory if it is missing.

References file_save_htaccess().

Referenced by file_unmanaged_copy(), and DirectoryTest\testFileCheckDirectoryHandling().

Here is the call graph for this function:

Here is the caller graph for this function:

file_htaccess_lines (   $private = TRUE)

Returns the standard .htaccess lines that Drupal writes to file directories.

Parameters
bool$private(Optional) Set to FALSE to return the .htaccess lines for a web-accessible public directory. The default is TRUE, which returns the .htaccess lines for a private directory that should not be web-accessible.
Returns
string The desired contents of the .htaccess file.
Deprecated:
in Drupal 8.0.x-dev and will be removed before Drupal 9.0.0. Use ::htaccessLines().
file_munge_filename (   $filename,
  $extensions,
  $alerts = TRUE 
)

Modifies a filename as needed for security purposes.

Munging a file name prevents unknown file extensions from masking exploit files. When web servers such as Apache decide how to process a URL request, they use the file extension. If the extension is not recognized, Apache skips that extension and uses the previous file extension. For example, if the file being requested is exploit.php.pps, and Apache does not recognize the '.pps' extension, it treats the file as PHP and executes it. To make this file name safe for Apache and prevent it from executing as PHP, the .php extension is "munged" into .php_, making the safe file name exploit.php_.pps.

Specifically, this function adds an underscore to all extensions that are between 2 and 5 characters in length, internal to the file name, and not included in $extensions.

Function behavior is also controlled by the configuration 'system.file:allow_insecure_uploads'. If it evaluates to TRUE, no alterations will be made, if it evaluates to FALSE, the filename is 'munged'. *

Parameters
$filenameFile name to modify.
$extensionsA space-separated list of extensions that should not be altered.
$alertsIf TRUE, drupal_set_message() will be called to display a message if the file name was changed.
Returns
string The potentially modified $filename.

References Drupal\config(), and t().

Referenced by NameMungingTest\testMungeIgnoreInsecure(), NameMungingTest\testMungeIgnoreWhitelisted(), NameMungingTest\testMungeNullByte(), NameMungingTest\testMunging(), and NameMungingTest\testUnMunge().

Here is the call graph for this function:

Here is the caller graph for this function:

file_prepare_directory ( $directory,
  $options = FILE_MODIFY_PERMISSIONS 
)

Checks that the directory exists and is writable.

Directories need to have execute permissions to be considered a directory by FTP servers, etc.

Parameters
$directoryA string reference containing the name of a directory path or URI. A trailing slash will be trimmed from a path.
$optionsA bitmask to indicate if the directory should be created if it does not exist (FILE_CREATE_DIRECTORY) or made writable if it is read-only (FILE_MODIFY_PERMISSIONS).
Returns
TRUE if the directory exists (or was created) and is writable. FALSE otherwise.

References drupal_chmod(), drupal_mkdir(), FILE_CREATE_DIRECTORY, FILE_MODIFY_PERMISSIONS, file_stream_wrapper_valid_scheme(), and Drupal\service().

Referenced by ImageStyle\createDerivative(), ImageStylesPathAndUrlTest\doImageStyleUrlAndPathTests(), AssetDumper\dump(), FileStorage\ensureStorage(), file_unmanaged_copy(), FileItem\generateSampleValue(), ImageItem\generateSampleValue(), hook_install(), EntityFile\import(), WebTestBase\initConfig(), BrowserTestBase\installDrupal(), LocaleUpdateBase\makePoFile(), MigrateFileTest\migrateDumpAlter(), BrowserTestBase\prepareEnvironment(), TestBase\run(), LocaleUpdateBase\setTranslationsDirectory(), FileTestForm\submitForm(), DirectoryTest\testFileCheckDirectoryHandling(), DownloadTest\testFileCreateUrl(), ToolkitGdTest\testGifTransparentImages(), and ToolkitGdTest\testManipulations().

Here is the call graph for this function:

Here is the caller graph for this function:

file_save_htaccess (   $directory,
  $private = TRUE,
  $force_overwrite = FALSE 
)

Creates a .htaccess file in the given directory.

Parameters
string$directoryThe directory.
bool$private(Optional) FALSE indicates that $directory should be a web-accessible directory. Defaults to TRUE which indicates a private directory.
bool$force_overwrite(Optional) Set to TRUE to attempt to overwrite the existing .htaccess file if one is already present. Defaults to FALSE.

References drupal_chmod(), file_stream_wrapper_uri_normalize(), Drupal\logger(), and Drupal\service().

Referenced by FileStorage\ensureStorage(), file_ensure_htaccess(), HtaccessUnitTest\testHtaccessSave(), and FileSaveHtaccessLoggingTest\testHtaccessSave().

Here is the call graph for this function:

Here is the caller graph for this function:

file_scan_directory (   $dir,
  $mask,
  $options = array(),
  $depth = 0 
)

Finds all files that match a given mask in a given directory.

Directories and files beginning with a dot are excluded; this prevents hidden files and directories (such as SVN working directories) from being scanned. Use the umask option to skip configuration directories to eliminate the possibility of accidentally exposing configuration information. Also, you can use the base directory, recurse, and min_depth options to improve performance by limiting how much of the filesystem has to be traversed.

Parameters
$dirThe base directory or URI to scan, without trailing slash.
$maskThe preg_match() regular expression for files to be included.
$optionsAn associative array of additional options, with the following elements:
  • 'nomask': The preg_match() regular expression for files to be excluded. There is no default.
  • 'callback': The callback function to call for each match. There is no default callback.
  • 'recurse': When TRUE, the directory scan will recurse the entire tree starting at the provided directory. Defaults to TRUE.
  • 'key': The key to be used for the returned associative array of files. Possible values are 'uri', for the file's URI; 'filename', for the basename of the file; and 'name' for the name of the file without the extension. Defaults to 'uri'.
  • 'min_depth': Minimum depth of directories to return files from. Defaults to 0.
$depthThe current depth of recursion. This parameter is only used internally and should not be passed in.
Returns
An associative array (keyed on the chosen key) of objects with 'uri', 'filename', and 'name' properties corresponding to the matched files.

References file_stream_wrapper_uri_normalize(), and Drupal\logger().

Referenced by JsCollectionOptimizer\deleteAll(), CssCollectionOptimizer\deleteAll(), WebTestBase\drupalGetTestFiles(), Updater\findInfoFile(), FileTranslation\findTranslationFiles(), ImageStyleFlushTest\getImageCount(), ImageAdminStylesTest\getImageCount(), ScanDirectoryTest\testOptionCallback(), ScanDirectoryTest\testOptionKey(), ScanDirectoryTest\testOptionMinDepth(), ScanDirectoryTest\testOptionNoMask(), ScanDirectoryTest\testOptionRecurse(), and ScanDirectoryTest\testReturn().

Here is the call graph for this function:

Here is the caller graph for this function:

file_stream_wrapper_uri_normalize (   $uri)

Normalizes a URI by making it syntactically correct.

A stream is referenced as "scheme://target".

The following actions are taken:

  • Remove trailing slashes from target
  • Trim erroneous leading slashes from target. e.g. ":///" becomes "://".
Parameters
string$uriString reference containing the URI to normalize.
Returns
string The normalized URI.

References file_stream_wrapper_valid_scheme(), file_uri_target(), and Drupal\service().

Referenced by ImageStyle\buildUrl(), file_build_uri(), file_save_htaccess(), file_scan_directory(), and file_unmanaged_copy().

Here is the call graph for this function:

Here is the caller graph for this function:

file_stream_wrapper_valid_scheme (   $scheme)

Checks that the scheme of a stream URI is valid.

Deprecated:
in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0. Use ::validScheme().

Referenced by ImageStyleDownloadController\deliver(), FileDownloadController\download(), file_prepare_directory(), file_stream_wrapper_uri_normalize(), file_valid_uri(), GDToolkit\save(), and StreamWrapperTest\testGetValidStreamScheme().

Here is the caller graph for this function:

file_unmanaged_copy (   $source,
  $destination = NULL,
  $replace = FILE_EXISTS_RENAME 
)

Copies a file to a new location without invoking the file API.

This is a powerful function that in many ways performs like an advanced version of copy().

  • Checks if $source and $destination are valid and readable/writable.
  • If file already exists in $destination either the call will error out, replace the file or rename the file based on the $replace parameter.
  • If the $source and $destination are equal, the behavior depends on the $replace parameter. FILE_EXISTS_REPLACE will error out. FILE_EXISTS_RENAME will rename the file until the $destination is unique.
  • Provides a fallback using realpaths if the move fails using stream wrappers. This can occur because PHP's copy() function does not properly support streams if open_basedir is enabled. See https://bugs.php.net/bug.php?id=60456
Parameters
$sourceA string specifying the filepath or URI of the source file.
$destinationA URI containing the destination that $source should be copied to. The URI may be a bare filepath (without a scheme). If this value is omitted, Drupal's default files scheme will be used, usually "public://".
$replaceReplace behavior when the destination file already exists:
  • FILE_EXISTS_REPLACE - Replace the existing file.
  • FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique.
  • FILE_EXISTS_ERROR - Do nothing and return FALSE.
Returns
The path to the new file, or FALSE in the event of an error.
See Also
file_copy()

References drupal_basename(), drupal_chmod(), drupal_dirname(), drupal_realpath(), file_build_uri(), file_destination(), file_ensure_htaccess(), file_prepare_directory(), file_stream_wrapper_uri_normalize(), Drupal\logger(), and t().

Referenced by ImageStyleFlushTest\createSampleImage(), ImageAdminStylesTest\createSampleImage(), ImageStylesPathAndUrlTest\doImageStyleUrlAndPathTests(), WebTestBase\drupalGetTestFiles(), file_unmanaged_move(), LocaleExportTest\setUp(), LocaleImportFunctionalTest\setUp(), ThemeSettingsForm\submitForm(), ImageFieldDefaultImagesTest\testDefaultImages(), TypedDataTest\testGetAndSet(), ImageItemTest\testImageItem(), FilterHtmlImageSecureTest\testImageSource(), NodeImportCreateTest\testImportCreate(), FieldImportCreateTest\testImportCreate(), UnmanagedCopyTest\testNonExistent(), UnmanagedCopyTest\testNormal(), and UnmanagedCopyTest\testOverwriteSelf().

Here is the call graph for this function:

Here is the caller graph for this function:

file_unmanaged_delete (   $path)

Deletes a file without database changes or hook invocations.

This function should be used when the file to be deleted does not have an entry recorded in the files table.

Parameters
$pathA string containing a file path or (streamwrapper) URI.
Returns
TRUE for success or path does not exist, or FALSE in the event of an error.
See Also
file_delete()
file_unmanaged_delete_recursive()

References drupal_unlink(), and Drupal\logger().

Referenced by JsCollectionOptimizer\deleteAll(), CssCollectionOptimizer\deleteAll(), ConfigController\downloadExport(), file_unmanaged_delete_recursive(), file_unmanaged_move(), ImageStyle\flush(), File\preDelete(), UnmanagedDeleteTest\testDirectory(), RetrieveFileTest\testFileRetrieving(), UnmanagedDeleteTest\testMissing(), and UnmanagedDeleteTest\testNormal().

Here is the call graph for this function:

Here is the caller graph for this function:

file_unmanaged_delete_recursive (   $path,
  $callback = NULL 
)

Deletes all files and directories in the specified filepath recursively.

If the specified path is a directory then the function will call itself recursively to process the contents. Once the contents have been removed the directory will also be removed.

If the specified path is a file then it will be passed to file_unmanaged_delete().

Note that this only deletes visible files with write permission.

Parameters
$pathA string containing either an URI or a file or directory path.
$callback(optional) Callback function to run on each file prior to deleting it and on each directory prior to traversing it. For example, can be used to modify permissions.
Returns
TRUE for success or if path does not exist, FALSE in the event of an error.
See Also
file_unmanaged_delete()

References drupal_rmdir(), and file_unmanaged_delete().

Referenced by BrowserTestBase\cleanupEnvironment(), ImageStyle\flush(), hook_uninstall(), UnmanagedDeleteRecursiveTest\testDirectory(), UnmanagedDeleteRecursiveTest\testEmptyDirectory(), RetrieveFileTest\testFileRetrieving(), UnmanagedDeleteRecursiveTest\testSingleFile(), and UnmanagedDeleteRecursiveTest\testSubDirectory().

Here is the call graph for this function:

Here is the caller graph for this function:

file_unmanaged_move (   $source,
  $destination = NULL,
  $replace = FILE_EXISTS_RENAME 
)

Moves a file to a new location without database changes or hook invocation.

Parameters
$sourceA string specifying the filepath or URI of the original file.
$destinationA string containing the destination that $source should be moved to. This must be a stream wrapper URI. If this value is omitted, Drupal's default files scheme will be used, usually "public://".
$replaceReplace behavior when the destination file already exists:
  • FILE_EXISTS_REPLACE - Replace the existing file.
  • FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique.
  • FILE_EXISTS_ERROR - Do nothing and return FALSE.
Returns
The URI of the moved file, or FALSE in the event of an error.
See Also
file_move()

References file_unmanaged_copy(), and file_unmanaged_delete().

Referenced by file_unmanaged_save_data(), ImageItem\generateSampleValue(), GDToolkit\save(), UnmanagedMoveTest\testMissing(), UnmanagedMoveTest\testNormal(), UnmanagedMoveTest\testOverwriteSelf(), and EntityFile\writeFile().

Here is the call graph for this function:

Here is the caller graph for this function:

file_unmanaged_save_data (   $data,
  $destination = NULL,
  $replace = FILE_EXISTS_RENAME 
)

Saves a file to the specified destination without invoking file API.

This function is identical to file_save_data() except the file will not be saved to the {file_managed} table and none of the file_* hooks will be called.

Parameters
$dataA string containing the contents of the file.
$destinationA string containing the destination location. This must be a stream wrapper URI. If no value is provided, a randomized name will be generated and the file will be saved using Drupal's default files scheme, usually "public://".
$replaceReplace behavior when the destination file already exists:
  • FILE_EXISTS_REPLACE - Replace the existing file.
  • FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique.
  • FILE_EXISTS_ERROR - Do nothing and return FALSE.
Returns
A string with the path of the resulting file, or FALSE on error.
See Also
file_save_data()

References drupal_tempnam(), file_unmanaged_move(), and t().

Referenced by FileEntityNormalizer\denormalize(), AssetDumper\dump(), AggregatorTestBase\getEmptyOpml(), AggregatorTestBase\getInvalidOpml(), AggregatorTestBase\getValidOpml(), ConfigExportUITest\testExport(), UnmanagedSaveDataTest\testFileSaveData(), and UpdateDeleteFileIfStaleTest\testUpdateDeleteFileIfStale().

Here is the call graph for this function:

Here is the caller graph for this function:

file_unmunge_filename (   $filename)

Undoes the effect of file_munge_filename().

Parameters
$filenameString with the filename to be unmunged.
Returns
An unmunged filename string.

Referenced by NameMungingTest\testUnMunge().

Here is the caller graph for this function:

file_upload_max_size ( )

Determines the maximum file upload size by querying the PHP settings.

Returns
A file size limit in bytes based on the PHP upload_max_filesize and post_max_size

Referenced by EditorImageDialog\buildForm(), ImportForm\buildForm(), FileItem\fieldSettingsForm(), FormBuilder\getFileUploadMaxSize(), and FileItem\getUploadValidators().

Here is the caller graph for this function:

file_uri_scheme (   $uri)
file_uri_target (   $uri)

Returns the part of a URI after the schema.

Parameters
string$uriA stream, referenced as "scheme://target" or "data:target".
Returns
string|bool A string containing the target (path), or FALSE if none. For example, the URI "public://sample/test.txt" would return "sample/test.txt".
See Also
file_uri_scheme()

Referenced by ImageStyle\buildUrl(), ImageStylesPathAndUrlTest\doImageStyleUrlAndPathTests(), file_stream_wrapper_uri_normalize(), ImageStyle\fileUriTarget(), hook_file_download(), hook_file_url_alter(), UserPictureTest\testCreateDeletePicture(), ConfigExportUITest\testExport(), FileItemTest\testFileItem(), UserPictureTest\testPictureOnNodeComment(), ThemeTest\testThemeSettings(), and StreamWrapperTest\testUriFunctions().

Here is the caller graph for this function:

file_url_transform_relative (   $file_url)

Transforms an absolute URL of a local file to a relative URL.

May be useful to prevent problems on multisite set-ups and prevent mixed content errors when using HTTPS + HTTP.

Parameters
string$file_urlA file URL of a local file as generated by file_create_url().
Returns
string If the file URL indeed pointed to a local file and was indeed absolute, then the transformed, relative URL to the local file. Otherwise: the original value of $file_url.
See Also
file_create_url()

References Drupal\request().

Referenced by EditorImageDialog\submitForm(), and UrlRewritingTest\testRelativeFileURL().

Here is the call graph for this function:

Here is the caller graph for this function:

file_valid_uri (   $uri)

Determines whether the URI has a valid scheme for file API operations.

There must be a scheme and it must be a Drupal-provided scheme like 'public', 'private', 'temporary', or an extension provided with hook_stream_wrappers().

Parameters
$uriThe URI to be tested.
Returns
TRUE if the URI is allowed.

References file_stream_wrapper_valid_scheme(), and Drupal\service().

Referenced by LibraryDiscoveryParser\fileValidUri().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

const FILE_STATUS_PERMANENT = 1