You are here

function imce_create_subdirectories in IMCE 6

Create directories under root according to path.

1 call to imce_create_subdirectories()
imce_form_subdirectory_submit in inc/subdir.inc
Subdirectory form submit.

File

inc/subdir.inc, line 33

Code

function imce_create_subdirectories($path, $root) {
  $directories = explode('/', str_replace('\\', '/', $path));
  $paths = array(
    $root,
  );
  foreach ($directories as $directory) {

    //no asterisks. create the directory(s)
    if (strpos($directory, '*') === FALSE) {

      //check and create directories under each path.
      foreach ($paths as $i => $path) {
        $paths[$i] = $path = $path . '/' . $directory;
        if (!file_check_location($path, $root) || !file_check_directory($path, FILE_CREATE_DIRECTORY)) {
          drupal_set_message(t('Specified path must be under file sytem path.'), 'error');
          return FALSE;
        }
      }
    }
    else {
      $newpaths = array();
      $regexp = str_replace('*', '.*', $directory);

      //add matching paths.
      foreach ($paths as $path) {
        $newpaths = array_merge($newpaths, imce_get_subdirectories($path, $regexp));
      }

      //no matching paths
      if (empty($newpaths)) {
        drupal_set_message(t('No matching subdirectories found.'), 'error');
        return FALSE;
      }
      $paths = $newpaths;
    }
  }
  return TRUE;
}