system_check_directory

Versions
4.7 – 7
system_check_directory($form_element)

Checks the existence of the directory specified in $form_element. This function is called from the system_settings form to check both core file directories (file_public_path, file_private_path, file_temporary_path).

Parameters

$form_element The form element containing the name of the directory to check.

Code

modules/system/system.module, line 1936

<?php
function system_check_directory($form_element) {
  $directory = $form_element['#value'];

  if (!is_dir($directory) && !drupal_mkdir($directory, NULL, TRUE)) {
    // If the directory does not exists and cannot be created.
    form_set_error($form_element['#parents'][0], t('The directory %directory does not exist and could not be created.', array('%directory' => $directory)));
    watchdog('file system', 'The directory %directory does not exist and could not be created.', array('%directory' => $directory), WATCHDOG_ERROR);
  }

  if (is_dir($directory) && !is_writable($directory) && !drupal_chmod($directory)) {
    // If the directory is not writable and cannont be made so.
    form_set_error($form_element['#parents'][0], t('The directory %directory exists but is not writable and could not be made writable.', array('%directory' => $directory)));
    watchdog('file system', 'The directory %directory exists but is not writable and could not be made writable.', array('%directory' => $directory), WATCHDOG_ERROR);
  }
  else {
    if ($form_element['#name'] == 'file_public_path') {
      // Create public .htaccess file.
      file_create_htaccess($directory, FALSE);
    }
    else {
      // Create private .htaccess file.
      file_create_htaccess($directory);
    }
  }

  return $form_element;
}
?>
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.