本文整理汇总了PHP中fs::explode_path方法的典型用法代码示例。如果您正苦于以下问题:PHP fs::explode_path方法的具体用法?PHP fs::explode_path怎么用?PHP fs::explode_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fs
的用法示例。
在下文中一共展示了fs::explode_path方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mkdir
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;
}
示例2: mkdir
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;
}
示例3: test_explode_relative_path
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');
}
示例4: mkdir
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;
}