You are here

function imce_create_subfolders in IMCE 5

create folder(s) under root according to path.

1 call to imce_create_subfolders()
imce_form_subfolder_form_submit in ./imce.module
subfolder form submit. (Forms API -> formID_submit)

File

./imce.module, line 852

Code

function imce_create_subfolders($path, $root) {
  $args = explode('/', str_replace('\\', '/', $path));
  $dirs = array(
    $root,
  );
  for ($i = 0; strlen($arg = $args[$i]); $i++) {
    if (strpos($arg, '*') === FALSE) {

      //no asterisks. create the folder(s)
      for ($j = 0; isset($dirs[$j]); $j++) {
        $dirs[$j] .= '/' . $arg;
        if (!file_check_location($dirs[$j], $root) || !file_check_directory($dirs[$j], TRUE)) {
          drupal_set_message(t('Specified path must be under file sytem path.'), 'error');
          return FALSE;
        }
      }
    }
    else {

      //get matching subfolders.
      $newdirs = array();
      $expr = str_replace('*', '.*', $arg);
      foreach ($dirs as $dir) {
        $newdirs = array_merge($newdirs, imce_get_subfolders($dir, $expr));
      }
      if (empty($newdirs)) {
        drupal_set_message(t('No matching sub-folders found.'), 'error');
        return FALSE;
      }
      $dirs = $newdirs;
    }
  }
  return TRUE;
}