You are here

function imce_mkdir_batch in IMCE Mkdir 7

Same name and namespace in other branches
  1. 6 imce_mkdir.inc \imce_mkdir_batch()

Batch adds directories.

1 call to imce_mkdir_batch()
imce_mkdir_submit in ./imce_mkdir.inc
Submits mkdir form.

File

./imce_mkdir.inc, line 73

Code

function imce_mkdir_batch(&$imce, $dirnames = array()) {
  if (!isset($imce['diradded'])) {
    $imce['diradded'] = array();
  }
  $parent = imce_dir_uri($imce);
  foreach ($dirnames as $dirname) {
    if (!preg_match('/^[A-Za-z0-9_\\-]+$/', $dirname)) {
      drupal_set_message(t('%dirname is not a valid directory name. It should contain only alphanumeric characters, hyphen and underscore.', array(
        '%dirname' => $dirname,
      )), 'error');
      continue;
    }
    $dirpath = $parent . $dirname;
    if (file_exists($dirpath)) {
      drupal_set_message(t('Subdirectory %dir already exists.', array(
        '%dir' => $dirname,
      )), 'error');
      continue;
    }
    if (!file_prepare_directory($dirpath, FILE_CREATE_DIRECTORY)) {
      drupal_set_message(t('Subdirectory %dir could not be created.', array(
        '%dir' => $dirname,
      )), 'error');
      continue;
    }
    drupal_set_message(t('Subdirectory %dir has been added.', array(
      '%dir' => $dirname,
    )));
    $imce['diradded'][] = $imce['subdirectories'][] = $dirname;
  }
}