(PHP 4, PHP 5)
mkdir — 新建目錄
說明
bool mkdir ( string$pathname
[, int $mode
= 0777
[, bool $recursive
= false
[, resource $context
]]] )
嘗試新建一個(gè)由 pathname 指定的目錄。
參數(shù)
pathname
目錄的路徑。
mode
默認(rèn)的 mode 是 0777,意味著最大可能的訪問權(quán)。有關(guān) mode 的更多信息請(qǐng)閱讀 chmod() 頁面。
Note:
mode
在 Windows 下被忽略。
注意也許想用八進(jìn)制數(shù)指定模式,也就是說該數(shù)應(yīng)以零打頭。模式也會(huì)被當(dāng)前的 umask 修改,可以用 umask() 來改變。
recursive
Allows the creation of nested directories specified in the
pathname
.
context
Note: 在 PHP 5.0.0 中增加了對(duì)上下文(Context)的支持。有關(guān)上下文(Context)的說明參見 Streams。
返回值
成功時(shí)返回 TRUE
, 或者在失敗時(shí)返回 FALSE
。
更新日志
版本
說明
5.0.0
添加 recursive
參數(shù)。
5.0.0
mkdir() 也可用于某些
URL 封裝協(xié)議。參見支持的協(xié)議和封裝協(xié)議
的列表看看 mkdir() 支持哪些 URL 封裝協(xié)議。
4.2.0
mode
成為可選項(xiàng)。
范例
Example #1 mkdir() 例子
<?php
mkdir("/path/to/my/dir", 0700);
?>
Example #2 通過 recursive
參數(shù)使用 mkdir()
<?php
// Desired folder structure
$structure = './depth1/depth2/depth3/';
// To create the nested structure, the $recursive parameter
// to mkdir() must be specified.
if (!mkdir($structure, 0, true)) {
die('Failed to create folders...');
}
// ...
?>
注釋
Note: 當(dāng)啟用 安全模式時(shí), PHP 會(huì)在執(zhí)行腳本時(shí)檢查被腳本操作的目錄是否與被執(zhí)行的腳本有相同的 UID(所有者)。
參見
is_dir() - 判斷給定文件名是否是一個(gè)目錄 rmdir() - 刪除目錄