Drupal API

file_check_directory

  • Drupal 5
  • Drupal 6
Хочешь помочь с переводом? Это очень просто и быстро. Лишь зарегистрируйся, и можешь тут же начать переводить.

includes/file.inc, строка 97

Версии
5 – 6
file_check_directory(&$directory, $mode = 0, $form_item = NULL)

Проверка каталога на существование и доступность для записи.

Параметры

$directory Строка содержащая адрес каталога.

$mode Логическое значение, обозначает стоит ли создать каталог, если он не существует, или сделать доступным для записи, если он доступен только для чтения

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

Возвращаемое значение

FALSE если каталог не найден, TRUE если каталог существует.

Связанные темы

▸ 9 функции вызывают file_check_directory()

▾ 9 функции вызывают 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
Объединяет и оптимизирует файлы CSS, размещая конечный файл в файловой директории.
drupal_build_js_cache in includes/common.inc
Объединяет JS файлы, размещая конечный файл в файловой директории.
file_check_path in includes/file.inc
Проверяет путь к директории или файлу.
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
user_admin_settings in modules/user/user.admin.inc
Form builder; Configure user settings for this site. See alsosystem_settings_form()
_locale_rebuild_js in includes/locale.inc
Создает(заменяет) JavaScript-файл перевода для указанного языка.

Код

<?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_set_message(t('The directory %directory has been created.', array('%directory' => $directory)));
      @chmod($directory, 0775); // Necessary for non-webserver users.
    }
    else {
      if ($form_item) {
        form_set_error($form_item, t('The directory %directory does not exist.', array('%directory' => $directory)));
      }
      return FALSE;
    }
  }
  // Check to see if the directory is writable.
  if (!is_writable($directory)) {
    if (($mode & FILE_MODIFY_PERMISSIONS) && @chmod($directory, 0775)) {
      drupal_set_message(t('The permissions of directory %directory have been changed to make it writable.', array('%directory' => $directory)));
    }
    else {
      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 (($fp = fopen("$directory/.htaccess", 'w')) && fputs($fp, $htaccess_lines)) {
      fclose($fp);
      chmod($directory .'/.htaccess', 0664);
    }
    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;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

Вход в систему

Что такое OpenID?
  • Регистрация
  • Забыли пароль?

Документация

  • Drupal 6
  • Константы
  • Файлы
  • Функции
  • Глобальные переменные
  • Разделы