file_prepare_directory

  1. drupal
    1. 8
    2. 7
Versions
7 – 8 file_prepare_directory(&$directory, $options = FILE_MODIFY_PERMISSIONS)

Check 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.

Related topics

▾ 25 functions call file_prepare_directory()

color_scheme_form_submit in modules/color/color.module
Submit handler for color change form.
DrupalUnitTestCase::setUp in modules/simpletest/drupal_web_test_case.php
Sets up unit test environment.
DrupalWebTestCase::setUp in modules/simpletest/drupal_web_test_case.php
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix.…
drupal_build_css_cache in includes/common.inc
Aggregates and optimizes CSS files into a cache file in the files directory.
drupal_build_js_cache in includes/common.inc
Aggregates JavaScript files into a cache file in the files directory.
FileDirectoryTest::testFileCheckDirectoryHandling in modules/simpletest/tests/file.test
Test directory handling functions.
FileDownloadTest::checkUrl in modules/simpletest/tests/file.test
Download a file from the URL generated by file_create_url().
file_example_create_directory_submit in examples/file_example/file_example.module
Submit handler for directory creation. Here we create a directory and set proper permissions on it using file_prepare_directory().
file_managed_file_save_upload in modules/file/file.module
Given a managed_file element, save any files that have been uploaded into it.
file_unmanaged_copy in includes/file.inc
Copies a file to a new location without invoking the file API.
hook_file_download in modules/system/system.api.php
Control access to private file downloads and specify HTTP headers.
ImageStylesPathAndUrlUnitTest::_testImageStyleUrlAndPath in modules/image/image.test
Test image_style_url().
ImageToolkitGdTestCase::testManipulations in modules/simpletest/tests/image.test
Since PHP can't visually check that our images have been manipulated properly, build a list of expected color values for each of the corners and the expected height and widths for the final images.
image_field_update_field in modules/image/image.module
Implements hook_field_update_field().
image_install in modules/image/image.install
Implements hook_install().
image_style_create_derivative in modules/image/image.module
Creates a new image derivative based on an image style.
SimpleTestFolderTestCase::testFolderSetup in modules/simpletest/simpletest.test
simpletest_verbose in modules/simpletest/drupal_web_test_case.php
Logs verbose message in a text file.
system_requirements in modules/system/system.install
Test and report Drupal installation requirements.
UpgradePathTestCase::setUp in modules/simpletest/tests/upgrade/upgrade.test
Override of DrupalWebTestCase::setUp() specialized for upgrade testing.
UserPictureTestCase::setUp in modules/user/user.test
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix.…
user_admin_settings in modules/user/user.admin.inc
Form builder; Configure user settings for this site.
user_save in modules/user/user.module
Save changes to a user account or add a new user.
_file_test_form_submit in modules/simpletest/tests/file_test.module
Process the upload.
_locale_rebuild_js in includes/locale.inc
(Re-)Creates the JavaScript translation file for a language.

Code

includes/file.inc, line 437

<?php
function file_prepare_directory(&$directory, $options = FILE_MODIFY_PERMISSIONS) {
  if (!file_stream_wrapper_valid_scheme(file_uri_scheme($directory))) {
    // Only trim if we're not dealing with a stream.
    $directory = rtrim($directory, '/\\');
  }

  // Check if directory exists.
  if (!is_dir($directory)) {
    // Let mkdir() recursively create directories and use the default directory
    // permissions.
    if (($options & FILE_CREATE_DIRECTORY) && @drupal_mkdir($directory, NULL, TRUE)) {
      return drupal_chmod($directory);
    }
    return FALSE;
  }
  // The directory exists, so check to see if it is writable.
  $writable = is_writable($directory);
  if (!$writable && ($options & FILE_MODIFY_PERMISSIONS)) {
    return drupal_chmod($directory);
  }

  return $writable;
}
?>