/**
* 创建目录
*
* @param string $dirPath 目录路径
* @return true成功,false失败
*/
public function makeDir($dirPath){
//处理目录
$dirPath = trim($dirPath, DS);
(strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') && ($dirPath = DS . $dirPath);
//如果目录存在 直接返回true
if(is_dir($dirPath)) return true;
//创建不存在的目录
$dirPath = explode(DS, $dirPath);
$path = '';
if(is_array($dirPath) && !empty($dirPath)){
foreach ($dirPath as $key => $value){
if(empty($value)) continue;
$path .= DS . $value;
(!$key) && (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') && ($path = trim($path, DS));
if(!is_dir($path)){
if(!@mkdir($path)) return false;
if(!@chmod($path, 0777)) return false;
}
if(!@chdir($path)) return false;
}
return true;
}
return false;
}
PHP创建目录函数
最新推荐文章于 2022-05-08 22:42:35 发布