You are here

function file_prepare_directory in Drupal 8

Same name and namespace in other branches
  1. 7 includes/file.inc \file_prepare_directory()

Checks that the directory exists and is writable.

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

Parameters

$directory: A string reference containing the name of a directory path or URI. A trailing slash will be trimmed from a path.

$options: A 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).

Return value

TRUE if the directory exists (or was created) and is writable. FALSE otherwise.

Deprecated

in drupal:8.7.0 and is removed from drupal:9.0.0. Use \Drupal\Core\File\FileSystemInterface::prepareDirectory().

Related topics

2 calls to file_prepare_directory()
FileSystemDeprecationTest::testDeprecatedFilePrepareDirectory in core/tests/Drupal/KernelTests/Core/File/FileSystemDeprecationTest.php
@expectedDeprecation file_prepare_directory() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\File\FileSystemInterface::prepareDirectory(). See https://www.drupal.org/node/3006851.
file_unmanaged_prepare in core/includes/file.inc
Internal function that prepares the destination for a file_unmanaged_copy or file_unmanaged_move operation.

File

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

Code

function file_prepare_directory(&$directory, $options = FileSystemInterface::MODIFY_PERMISSIONS) {
  @trigger_error('file_prepare_directory() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \\Drupal\\Core\\File\\FileSystemInterface::prepareDirectory(). See https://www.drupal.org/node/3006851.', E_USER_DEPRECATED);
  return \Drupal::service('file_system')
    ->prepareDirectory($directory, $options);
}