在看php-openid的源码的时候,发现它实现的创建多级目录的方法的思想很巧妙,特将起代码记录下来:
/**
* Create dir_name as a directory if it does not exist. If it
* exists, make sure that it is, in fact, a directory. Returns
* true if the operation succeeded; false if not.
*
* @access private
*/
static
function
ensureDir(
$dir_name
)
{
if
(
is_dir
(
$dir_name
) || @
mkdir
(
$dir_name
)) {
return
true;
}
else
{
$parent_dir
= dirname(
$dir_name
);
// Terminal case; there is no parent directory to create.
if
(
$parent_dir
==
$dir_name
) {
return
true;
}
return
(Auth_OpenID::ensureDir(
$parent_dir
) && @
mkdir
(
$dir_name
));
}
}