file_prepare_directory

  1. drupal
    1. 7
Versions
7 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

▾ 17 functions call file_prepare_directory()

color_scheme_form_submit in drupal/modules/color/color.module
Submit handler for color change form.
DrupalUnitTestCase::setUp in drupal/modules/simpletest/drupal_web_test_case.php
Sets up unit test environment.
DrupalWebTestCase::setUp in drupal/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 drupal/includes/common.inc
Aggregates and optimizes CSS files into a cache file in the files directory.
drupal_build_js_cache in drupal/includes/common.inc
Aggregates JavaScript files into a cache file in the files directory.
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 drupal/modules/file/file.module
Given a managed_file element, save any files that have been uploaded into it.
file_unmanaged_copy in drupal/includes/file.inc
Copies a file to a new location without invoking the file API.
hook_file_download in drupal/modules/system/system.api.php
Control access to private file downloads and specify HTTP headers.
image_install in drupal/modules/image/image.install
Implements hook_install().
image_style_create_derivative in drupal/modules/image/image.module
Creates a new image derivative based on an image style.
simpletest_verbose in drupal/modules/simpletest/drupal_web_test_case.php
Logs verbose message in a text file.
system_requirements in drupal/modules/system/system.install
Test and report Drupal installation requirements.
user_admin_settings in drupal/modules/user/user.admin.inc
Form builder; Configure user settings for this site.
user_save in drupal/modules/user/user.module
Save changes to a user account or add a new user.
_file_test_form_submit in drupal/modules/simpletest/tests/file_test.module
Process the upload.
_locale_rebuild_js in drupal/includes/locale.inc
(Re-)Creates the JavaScript translation file for a language.

Code

drupal/includes/file.inc, line 438

<?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;
}
?>