9 * create full directory structure
16 function smarty_core_create_dir_structure($params, &$smarty)
18 if (!file_exists($params['dir'])) {
19 $_open_basedir_ini = ini_get('open_basedir');
21 if (DIRECTORY_SEPARATOR
=='/') {
22 /* unix-style paths */
23 $_dir = $params['dir'];
24 $_dir_parts = preg_split('!/+!', $_dir, -1, PREG_SPLIT_NO_EMPTY
);
25 $_new_dir = ($_dir{0}=='/') ?
'/' : getcwd().'/';
26 if($_use_open_basedir = !empty($_open_basedir_ini)) {
27 $_open_basedirs = explode(':', $_open_basedir_ini);
31 /* other-style paths */
32 $_dir = str_replace('\\','/', $params['dir']);
33 $_dir_parts = preg_split('!/+!', $_dir, -1, PREG_SPLIT_NO_EMPTY
);
34 if (preg_match('!^((//)|([a-zA-Z]:/))!', $_dir, $_root_dir)) {
35 /* leading "//" for network volume, or "[letter]:/" for full path */
36 $_new_dir = $_root_dir[1];
37 /* remove drive-letter from _dir_parts */
38 if (isset($_root_dir[3])) array_shift($_dir_parts);
41 $_new_dir = str_replace('\\', '/', getcwd()).'/';
45 if($_use_open_basedir = !empty($_open_basedir_ini)) {
46 $_open_basedirs = explode(';', str_replace('\\', '/', $_open_basedir_ini));
51 /* all paths use "/" only from here */
52 foreach ($_dir_parts as $_dir_part) {
53 $_new_dir .= $_dir_part;
55 if ($_use_open_basedir) {
56 // do not attempt to test or make directories outside of open_basedir
57 $_make_new_dir = false;
58 foreach ($_open_basedirs as $_open_basedir) {
59 if (substr($_new_dir, 0, strlen($_open_basedir)) == $_open_basedir) {
60 $_make_new_dir = true;
65 $_make_new_dir = true;
68 if ($_make_new_dir && !file_exists($_new_dir) && !@mkdir
($_new_dir, $smarty->_dir_perms
) && !is_dir($_new_dir)) {
69 $smarty->trigger_error("problem creating directory '" . $_new_dir . "'");
77 /* vim: set expandtab: */