function tripal_create_files_dir
2.x tripal_core.files.api.inc | tripal_create_files_dir($module_name, $path = FALSE) |
3.x tripal.files.api.inc | tripal_create_files_dir($module_name, $path = FALSE) |
Creates a directory for a module in the Drupal's public files directory.
Previously it was recommended that this function be called during installation of the module in the .install file. However this causes permission problems if the module is installed via drush with a user account that is not the same as the web user. Therefore, this function should not be called in a location accessiblve via a drush command. The tripal_get_files_dir() and tripal_get_files_stream() will automatically create the directory if it doesn't exist so there is little need to call this function directly.
Parameters
$module_name: the name of the module being installed
$path: Optional sub-path to create
Related topics
4 calls to tripal_create_files_dir()
- tripal_create_moddir in legacy/
tripal_core/ api/ tripal_core.DEPRECATED.inc - tripal_create_mod_subdir in legacy/
tripal_core/ api/ tripal_core.DEPRECATED.inc - tripal_get_files_dir in tripal/
api/ tripal.files.api.inc - Retrieves the Drupal relative directory for a Tripal module.
- tripal_get_files_stream in tripal/
api/ tripal.files.api.inc - Retrieves the Drupal stream (e.g. public://...) for a Tripal module.
2 string references to 'tripal_create_files_dir'
- tripal_create_moddir in legacy/
tripal_core/ api/ tripal_core.DEPRECATED.inc - tripal_create_mod_subdir in legacy/
tripal_core/ api/ tripal_core.DEPRECATED.inc
File
- tripal/
api/ tripal.files.api.inc, line 37 - Provides an application programming interface (API) for managing files within the Tripal data directory structure.
Code
function tripal_create_files_dir($module_name, $path = FALSE) {
// if the path is not supplied then assume they want to create the base files
// directory for the specified module
if (!$path) {
// make the data directory for this module
$data_dir = tripal_get_files_dir() . "/$module_name";
if (!file_prepare_directory($data_dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
$message = "Cannot create directory $data_dir. This module may not " .
"behave correctly without this directory. Please create " .
"the directory manually or fix the problem and reinstall.";
drupal_set_message(check_plain(t($message)), 'error');
tripal_report_error('tripal', TRIPAL_ERROR, $message, array());
}
}
else {
// make sure the module data directory exists, we make a recursive call
// but without the path
tripal_create_files_dir($module_name);
// now make sure the sub dir exists
$sub_dir = tripal_get_files_dir() . '/' . $module_name . '/' . $path;
if (!file_prepare_directory($sub_dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
$message = "Can not create directory $sub_dir. ";
drupal_set_message(check_plain(t($message)), 'error');
tripal_report_error('tripal', TRIPAL_ERROR, $message, array());
}
}
}