function file_prepare_directory


Error message

User warning: The following module is missing from the file system: theme/theme. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1156 of /var/www/html/elmsln_community/
cis7 file_prepare_directory(&$directory, $options = FILE_MODIFY_PERMISSIONS)
cle7 file_prepare_directory(&$directory, $options = FILE_MODIFY_PERMISSIONS)
elmsmedia7 file_prepare_directory(&$directory, $options = FILE_MODIFY_PERMISSIONS)
icor7 file_prepare_directory(&$directory, $options = FILE_MODIFY_PERMISSIONS)
meedjum_blog7 file_prepare_directory(&$directory, $options = FILE_MODIFY_PERMISSIONS)
mooc7 file_prepare_directory(&$directory, $options = FILE_MODIFY_PERMISSIONS)

Checks that the directory exists and is writable.

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


$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

70 calls to file_prepare_directory()
advagg_create_subfile in sites/all/modules/ulmus/advagg/
Write CSS parts to disk; used when CSS selectors in one file is > 4096.
advagg_get_root_files_dir in sites/all/modules/ulmus/advagg/advagg.module
Get the CSS & JS path for advagg.
advagg_mod_admin_settings_form_validate in sites/all/modules/ulmus/advagg/advagg_mod/
Make sure the unified multisite directory was created correctly.
advagg_mod_advagg_get_root_files_dir_alter in sites/all/modules/ulmus/advagg/advagg_mod/advagg_mod.module
Implements hook_advagg_get_root_files_dir_alter().
advagg_requirements in sites/all/modules/ulmus/advagg/advagg.install
Implements hook_requirements().

... See full list


includes/, line 430
API for handling file uploads and server file management.


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;