How do I create a directory from hook_install of a module in Drupal 7?
Actually, I know how to create a directory = mkdir.
However, I need to pass it a full absolute path in the server, and I don't know how to get the relevant path in hook_install. I tried using开发者_运维问答 base_path(), but it returned '/'.The path I want is sites/default/files (inside "files" I create the directory).
Thanks.
Please use the proper APIs.
$directory = file_default_scheme() . '://yourdir';
file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
Did you try mkdir('sites/default/files/yourdir')
? If so, where does that create the directory? If not, why not?
Relative directory names are resolved based on the working directory. The working directory in Drupal is usually the directory in which your install.php
and index.php
is located.
精彩评论