1 file_example.module 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

File

modules/examples/file_example/file_example.module, line 423
Hook implementations for the File Example module.

Code

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)) {
    backdrop_set_message(t('Failed to create %directory.', array('%directory' => $directory)), 'error');
  }
  else {
    $result = is_dir($directory);
    backdrop_set_message(t('Directory %directory is ready for use.', array('%directory' => $directory)));
    $_SESSION['file_example_default_directory'] = $directory;
  }
}