file_check_directory

  1. drupal
    1. drupal6
    2. drupal7
Versionen
drupal6 – drupal7 file_check_directory(&$directory, $mode = 0, $form_item = NULL)

Check that the directory exists and is writable.

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

Übergabeparameter

$directory A string containing the name of a directory path.

$mode 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).

$form_item An optional string containing the name of a form item that any errors will be attached to. This is useful for settings forms that require the user to specify a writable directory. If it can't be made to work, a form error will be set preventing them from saving the settings.

Rückgabewert

FALSE when directory not found, or TRUE when directory exists.

Verwandte Themen

▾ 14 functions call file_check_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.
FileDirectoryTest::testFileCheckDirectory in modules/simpletest/tests/file.test
Test the file_directory_path() function.
file_check_path in includes/file.inc
Checks path to see if it is a directory, or a directory/file.
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.
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.…
simpletest_install in modules/simpletest/simpletest.install
Implementation of hook_install().
system_check_directory in modules/system/system.module
Checks the existence of the directory specified in $form_element. This function is called from the system_settings form to check both the file_directory_path and file_directory_temp directories. If validation fails, the form element is flagged with an…
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
UserPictureTestCase::setUp in modules/user/user.test
user_admin_settings in modules/user/user.admin.inc
Form builder; Configure user settings for this site.
_locale_rebuild_js in includes/locale.inc
(Re-)Creates the JavaScript translation file for a language.

Code

includes/file.inc, line 154

<?php
function file_check_directory(&$directory, $mode = 0, $form_item = NULL) {
  $directory = rtrim($directory, '/\\');

  // Check if directory exists.
  if (!is_dir($directory)) {
    if (($mode & FILE_CREATE_DIRECTORY) && @mkdir($directory)) {
      drupal_chmod($directory);
    }
    else {
      if ($form_item) {
        form_set_error($form_item, t('The directory %directory does not exist.', array('%directory' => $directory)));
        watchdog('file system', 'The directory %directory does not exist.', array('%directory' => $directory), WATCHDOG_ERROR);
      }
      return FALSE;
    }
  }

  // Check to see if the directory is writable.
  if (!is_writable($directory)) {
    // If not able to modify permissions, or if able to, but chmod
    // fails, return false.
    if (!$mode || (($mode & FILE_MODIFY_PERMISSIONS) && !drupal_chmod($directory))) {
      if ($form_item) {
        form_set_error($form_item, t('The directory %directory is not writable', array('%directory' => $directory)));
        watchdog('file system', 'The directory %directory is not writable, because it does not have the correct permissions set.', array('%directory' => $directory), WATCHDOG_ERROR);
      }
      return FALSE;
    }
  }

  if ((file_directory_path() == $directory || file_directory_temp() == $directory) && !is_file("$directory/.htaccess")) {
    $htaccess_lines = "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006\nOptions None\nOptions +FollowSymLinks";
    if (file_put_contents("$directory/.htaccess", $htaccess_lines)) {
      drupal_chmod("$directory/.htaccess");
    }
    else {
      $variables = array('%directory' => $directory, '!htaccess' => '<br />' . nl2br(check_plain($htaccess_lines)));
      form_set_error($form_item, t("Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines: <code>!htaccess</code>", $variables));
      watchdog('security', "Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines: <code>!htaccess</code>", $variables, WATCHDOG_ERROR);
    }
  }

  return TRUE;
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen