function mkdir_chmod($path, $mode = 0777) { if (is_dir($path)) { return true; } $result = mkdir($path, $mode, true); if ($result) { $path_arr = explode('/', $path); $path_str = ''; foreach ($path_arr as $val) { $path_str .= $val . '/'; $a = chmod($path_str, $mode); } } return $result; }