function mkdir($dir, $perm = 0777, $parents = true) { $dir = fs::clean_path($dir); if (is_dir($dir)) { return true; } if (!$parents) { return fs::_do_mkdir($dir, $perm); } $separator = fs::separator(); $dir_elements = fs::explode_path($dir); if (count($dir_elements) == 0) { return true; } if (!$dir_elements[0]) { array_shift($dir_elements); $current_dir = $separator . array_shift($dir_elements); } else { $current_dir = array_shift($dir_elements); } if (!fs::_do_mkdir($current_dir, $perm)) { return false; } for ($i = 0; $i < count($dir_elements); $i++) { $current_dir .= $separator . $dir_elements[$i]; if (!fs::_do_mkdir($current_dir, $perm)) { return false; } } return true; }
function mkdir($dir, $perm = 0777, $parents = true) { $dir = fs::clean_path($dir); if (is_dir($dir)) { return true; } if (!$parents) { return fs::_do_mkdir($dir, $perm); } $separator = fs::separator(); $path_elements = fs::explode_path($dir); if (count($path_elements) == 0) { return true; } $index = fs::_get_first_existing_path_index($path_elements, $separator); if ($index === false) { //this is really a fatal case... return false; } $offset_path = ''; for ($i = 0; $i < $index; $i++) { $offset_path .= $path_elements[$i] . $separator; } for ($i = $index; $i < count($path_elements); $i++) { $offset_path .= $path_elements[$i] . $separator; if (!fs::_do_mkdir($offset_path, $perm)) { return false; } } return true; }
function test_explode_relative_path() { $path = fs::explode_path('tmp\\../tmp/wow////hey/'); $this->assertEqual(sizeof($path), 3); $this->assertEqual($path[0], 'tmp'); $this->assertEqual($path[1], 'wow'); $this->assertEqual($path[2], 'hey'); $path = fs::explode_path('tmp\\../tmp/wow////hey'); // no trailing slash $this->assertEqual(sizeof($path), 3); $this->assertEqual($path[0], 'tmp'); $this->assertEqual($path[1], 'wow'); $this->assertEqual($path[2], 'hey'); }
function mkdir($dir, $perm=0777, $parents=true) { $dir = fs :: clean_path($dir); if(is_dir($dir)) return true; if(!$parents) return fs :: _do_mkdir($dir, $perm); $separator = fs :: separator(); $path_elements = fs :: explode_path($dir); if (count($path_elements) == 0) return true; $index = fs :: _get_first_existent_path_index($path_elements, $separator); if($index === false) { debug :: write_error('failed to find first existent path', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__); return false; } $offset_path = ''; for ($i=0; $i < $index; $i++) { $offset_path .= $path_elements[$i] . $separator; } for ($i=$index; $i < count($path_elements); $i++) { $offset_path .= $path_elements[$i] . $separator; if (!fs :: _do_mkdir($offset_path, $perm)) return false; } return true; }