file_example_create_directory_submit

  1. drupal
    1. 8
    2. 7
Versions
7 – 8 file_example_create_directory_submit($form, &$form_state)

Submit handler for directory creation. Here we create a directory and set proper permissions on it using file_prepare_directory().

Related topics

Code

examples/file_example/file_example.module, line 397

<?php
function file_example_create_directory_submit($form, &$form_state) {
  $directory = $form_state['values']['directory_name'];

  // The options passed to file_prepare_directory are a bitmask, so we can
  // specify either FILE_MODIFY_PERMISSIONS (set permissions on the directory),
  // FILE_CREATE_DIRECTORY, or both together:
  // FILE_MODIFY_PERMISSIONS | FILE_CREATE_DIRECTORY.
  // FILE_MODIFY_PERMISSIONS will set the permissions of the directory by
  // by default to 0755, or to the value of the variable 'file_chmod_directory'.
  if (!file_prepare_directory($directory, FILE_MODIFY_PERMISSIONS | FILE_CREATE_DIRECTORY)) {
    drupal_set_message(t('Failed to create %directory.', array('%directory' => $directory)), 'error');
  }
  else {
    $result = is_dir($directory);
    drupal_set_message(t('Directory %directory is ready for use.', array('%directory' => $directory)));
    $_SESSION['file_example_default_directory'] = $directory;
  }
}
?>