PHP 循环检测并生成目录 chkDir($dirname,$split='/')
2015-02-07 09:24
204 查看
自己写的,在MVC框架里面可以直接使用!
[php] view
plaincopy
/**
* @author F.Z.B <default7@zbphp.com>
* @description 循环检测目录
*
* @param $dir
* @param string $split
*
* @return bool
*/
function chkDir($dir, $split = '/')
{
preg_match_all('/([^\/]+)\/?/', str_replace('\\', '/', trim($dir)), $matches);
if (!empty($matches[1])) {
$dir = '.';
$i = 0;
$len = count($matches[1]);
while (true) {
if ($i >= $len) break;
$dir .= $split . $matches[1][$i];
if (!is_dir($dir) && mkdir($dir, 0777)) @chmod($dir, 0777);
$i++;
}
}
return true;
}
用法:
[php] view
plaincopy
$savePath = '/Uploads/clubImg/2014/09/27/1122_201409272046541186.jpg
chkDir( dirname($savePath) );
[php] view
plaincopy
/**
* @author F.Z.B <default7@zbphp.com>
* @description 循环检测目录
*
* @param $dir
* @param string $split
*
* @return bool
*/
function chkDir($dir, $split = '/')
{
preg_match_all('/([^\/]+)\/?/', str_replace('\\', '/', trim($dir)), $matches);
if (!empty($matches[1])) {
$dir = '.';
$i = 0;
$len = count($matches[1]);
while (true) {
if ($i >= $len) break;
$dir .= $split . $matches[1][$i];
if (!is_dir($dir) && mkdir($dir, 0777)) @chmod($dir, 0777);
$i++;
}
}
return true;
}
用法:
[php] view
plaincopy
$savePath = '/Uploads/clubImg/2014/09/27/1122_201409272046541186.jpg
chkDir( dirname($savePath) );
相关文章推荐
- PHP 循环检测并生成目录 chkDir($dirname,$split='/')
- dirname(__FILE__) 与 PHP define() 及例子define('root',dirname(__file__))
- php循环检测目录是否存在并创建(循环创建目录)
- 检查某目录或是文件是否存在 file_exists( ABSPATH . 'wp-config.php')
- php循环检测目录是否存在并创建(循环创建目录)
- (转载)php循环检测目录是否存在并创建(循环创建目录)
- 检测自己的php是否可以访问mysql,以及“Class 'MySQLi' not found”的解决方法
- php循环检测目录是否存在并创建(循环创建目录)
- D'Fusion中lua调用c++生成的dll库,并且lua调用c++代码(遍历文件夹中整个目录)
- php循环检测目录是否存在并创建
- 原来php的dirname不检测文件是否存在
- PHP中$GLOBALS['HTTP_RAW_POST_DATA'] 和 $_POST
- php+jquery读取文件目录生成树形结构
- AES Encryption to Match PHP's Mcrypt Extension
- sql 缺少注释的结尾标记 '*/'。 '*' 附近有语法错误。 在注释中包含 GO 命令会生成一个错误信息
- PHP Maximum function nesting level of '100' reached 问题
- 获取HTML'checkbox' 的值/Split
- DOS总生成目录文件的tree命令--tree /f e:/book >e:/list.txt
- php提示错误:Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO)
- PHP3 'safe_mode' 失效漏洞