file_prepare_directory

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 modules/color/color.module
Submit handler for color change form.
drupal_build_css_cache in includes/common.inc
Aggregate and optimize CSS files, putting them in the files directory.
drupal_build_js_cache in includes/common.inc
Aggregate JS files, putting them in the files 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
Copy a file to a new location without calling any hooks or making any changes to the database.
hook_file_download in modules/system/system.api.php
Control access to private file downloads and specify HTTP headers.
image_install in modules/image/image.install
Implement hook_install().
image_style_create_derivative in modules/image/image.module
Create a new image based on an image style.
simpletest_install in modules/simpletest/simpletest.install
Implement hook_install().
simpletest_verbose in modules/simpletest/drupal_web_test_case.php
Log verbose message in a text file.
system_requirements in modules/system/system.install
Test and report Drupal installation requirements.
system_theme_settings in modules/system/system.admin.inc
Form builder; display theme configuration for entire site and individual themes.
upload_form_alter in modules/upload/upload.module
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 355

<?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;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.