循环新建文件夹函数
1 if ( !defined('DIRECTORY_SEPARATOR') )
2 define('DIRECTORY_SEPARATOR', '/');
3 define('ROOT', str_replace("\\", "/", $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR));
4 /**
5 * Creates directory
6 *
7 * @access private
8 * @param string $path Path to create
9 * @param integer $mode Optional permissions
10 * @return boolean Success
11 */
12 function _mkdir($path, $mode = 0777) {
13 $flag = true;
14 $subPath = '';
15 if ( $flag ) {
16 if ( strpos($path, '/') ) {
17 $folderList = explode('/', $path);
18 for ( $i = 0; $i < count($folderList); $i++ ) {
19 if ( $i ) {
20 $subPath = $subPath . '/' . $folderList[$i];
21 } else {
22 $subPath = $subPath . $folderList[$i];
23 }
24 $path = ROOT . $subPath;
25 if ( is_dir($path) ) continue;
26 $old = umask(0);
27 $res = @mkdir($path, $mode);
28 umask($old);
29 if ( !$res ) {
30 $flag = false;
31 break;
32 }
33 }
34 } else {
35 $path = ROOT . $path;
36 if ( $path ) return $flag;
37 $old = umask(0);
38 $res = @mkdir($path, $mode);
39 umask($old);
40 }
41 }
42
43 return $flag;
44 }
1 $res = _mkdir('upload/images');
2 if (!$res) echo 'create folder failed';
3 echo 'successfully';