文件系統(tǒng)輔助函數(shù)?
目錄輔助函數(shù)文件包含的函數(shù)協(xié)助目錄運(yùn)行。
通用函數(shù)?
接下來(lái)的函數(shù)是通用的:
-
directory_map
($source_dir[, $directory_depth = 0[, $hidden = FALSE]])? 參數(shù): - $source_dir (string) – 資源目錄路徑
- $directory_depth (int) – 遍歷目錄量度 (0 = 完全遞歸, 1 = 最近目錄, 等等)
- $hidden (bool) – 是否包含隱藏目錄
返回: 文件數(shù)組
返回類(lèi)型: array
例如:
$map = directory_map('./mydirectory/');
注解
路徑幾乎常常與你的主要 index.php 文件有關(guān)系。
子文件夾包含的目錄還會(huì)被映射。如果你希望控制遞歸量度,你會(huì)使用秒?yún)?shù)(整型)。1 的量度將僅僅映射根層目錄:
$map = directory_map('./mydirectory/', 1);
默認(rèn)情況下,在返回?cái)?shù)組里將不會(huì)被包含隱藏文件。推翻這個(gè)運(yùn)轉(zhuǎn)狀態(tài),你也許要設(shè)置第三個(gè)參數(shù)為真(boolean):
$map = directory_map('./mydirectory/', FALSE, TRUE);
每一個(gè)文件名將是數(shù)組索引,它包含的文件將會(huì)被用數(shù)值編入索引。下面是一個(gè)典型數(shù)組:
Array ( [libraries] => Array ( [0] => benchmark.html [1] => config.html ["database/"] => Array ( [0] => query_builder.html [1] => binds.html [2] => configuration.html [3] => connecting.html [4] => examples.html [5] => fields.html [6] => index.html [7] => queries.html ) [2] => email.html [3] => file_uploading.html [4] => image_lib.html [5] => input.html [6] => language.html [7] => loader.html [8] => pagination.html [9] => uri.html )
如果沒(méi)有找到結(jié)果,將會(huì)返回空數(shù)組。
-
write_file
($path, $data[, $mode = 'wb'])? 參數(shù): - $path (string) – File 路徑
- $data (string) – 數(shù)據(jù)寫(xiě)入 file
- $mode (string) –
fopen()
模式
返回: 如果寫(xiě)入成功為 TRUE , 萬(wàn)一錯(cuò)誤是 FALSE
返回類(lèi)型: bool
將數(shù)據(jù)寫(xiě)入指定路徑中的文件。如果文件不存在,這個(gè)函數(shù)將創(chuàng)建文件。
例如:
$data = 'Some file data'; if ( ! write_file('./path/to/file.php', $data)) { echo 'Unable to write the file'; } else { echo 'File written!'; }
你能隨意地通過(guò)第三個(gè)參數(shù)設(shè)置寫(xiě)模式:
write_file('./path/to/file.php', $data, 'r+'); 默認(rèn)模式是'wb'. 模式選項(xiàng)請(qǐng)查看 `PHP 用戶指導(dǎo) <http://php.net/manual/en/function.fopen.php>`_ .
注解
這個(gè)函數(shù)向文件里寫(xiě)入數(shù)據(jù)要按順序,它的權(quán)限必須被設(shè)置成可寫(xiě)的。如果文件已經(jīng)不存在, 那么目錄下的文件必須是可寫(xiě)的。
注解
路徑關(guān)聯(lián)你的主站的 index.php 文件,不是你的 controller 或者 view 文件。 CodeIgniter 用前端 controller 因此路徑常常關(guān)聯(lián)主站的 index.
注解
當(dāng)寫(xiě)入文件時(shí)函數(shù)捕獲了文件上獨(dú)占的鎖定。
-
delete_files
($path[, $del_dir = FALSE[, $htdocs = FALSE]])? 參數(shù): - $path (string) – 目錄路徑
- $del_dir (bool) – 是否也刪除目錄
- $htdocs (bool) – 是否跳過(guò)刪除 .htaccess 和 index page 文件
返回: 萬(wàn)一為FALSE,TRUE 為真
返回類(lèi)型: bool
刪除所有包含在備用路徑里的文件。
例如:
delete_files('./path/to/directory/');
如果第二個(gè)參數(shù)設(shè)置為 TRUE,包含備用根路徑的任何目錄將也會(huì)被刪除。
例如:
delete_files('./path/to/directory/', TRUE);
注解
文件必須是可寫(xiě)的而已經(jīng)歸屬至系統(tǒng)的文件原則上已被刪除。
-
get_filenames
($source_dir[, $include_path = FALSE])? 參數(shù): - $source_dir (string) – 目錄路徑
- $include_path (bool) – 作為文件名的部分是否包含路徑
返回: 文件名數(shù)組
返回類(lèi)型: array
函數(shù)里取服務(wù)器路徑輸入并返回包含所有文件名的數(shù)組。設(shè)置第二參數(shù)為 TRUE 文件路徑能很隨意的被添加到文件名里。
例如:
$controllers = get_filenames(APPPATH.'controllers/');
-
get_dir_file_info
($source_dir, $top_level_only)? 參數(shù): - $source_dir (string) – 目錄路徑
- $top_level_only (bool) – 是否僅僅查看特殊目錄 (不包含子目錄)
返回: 數(shù)組涵蓋的信息在備用目錄的內(nèi)容中
返回類(lèi)型: array
閱讀指定的目錄并建立包含文件名,文件大小,日期和權(quán)限的數(shù)組。 如果傳送第二個(gè)參數(shù)被阻止成 FALSE 包含指定目錄的子文件夾一定是只讀的,如同這是個(gè)強(qiáng)調(diào)操作。
事例:
$models_info = get_dir_file_info(APPPATH.'models/');
-
get_file_info
($file[, $returned_values = array('name', 'server_path', 'size', 'date')])? 參數(shù): - $file (string) – File 路徑
- $returned_values (array) – 任何返回的信息類(lèi)型
返回: 在指定文件上的數(shù)組包含的信息或失效的 FALSE
返回類(lèi)型: array
約定的文件和路徑,文件返回(隨意地) the name, path, size and date modified 屬性信息。 第二參數(shù)允許你明確地聲明任何你想返回的信息。
有效的
$returned_values
選項(xiàng)是: name, size, date, readable, writeable, executable 和 fileperms.
-
symbolic_permissions
($perms)? 參數(shù): - $perms (int) – 權(quán)限
返回: 象征權(quán)限的 string
返回類(lèi)型: string
抓取數(shù)值權(quán)限(就像是被
fileperms()
返回的)并且返回文件權(quán)限的標(biāo)準(zhǔn)符號(hào)記號(hào)。echo symbolic_permissions(fileperms('./index.php')); // -rw-r--r--
-
octal_permissions
($perms)? 參數(shù): - $perms (int) – 權(quán)限
返回: 八進(jìn)制權(quán)限的 string
返回類(lèi)型: string
抓取數(shù)值權(quán)限(就像是被
fileperms()
返回的)并且返回文件權(quán)限的一個(gè)由三個(gè)字母組成的八進(jìn)制記號(hào)。echo octal_permissions(fileperms('./index.php')); // 644
-
set_realpath
($path[, $check_existance = FALSE])? 參數(shù): - $path (string) – 路徑
- $check_existance (bool) – 如果路徑確實(shí)存在是否要去檢查
返回: 絕對(duì)路徑
返回類(lèi)型: string
函數(shù)會(huì)返回不帶符號(hào)鏈接的服務(wù)器路徑或者有關(guān)聯(lián)的目錄結(jié)構(gòu)。 如果路徑不能決定選項(xiàng)的次一級(jí)爭(zhēng)議將觸發(fā)一個(gè)錯(cuò)誤。
例如:
$file = '/etc/php5/apache2/php.ini'; echo set_realpath($file); // 輸出 '/etc/php5/apache2/php.ini' $non_existent_file = '/path/to/non-exist-file.txt'; echo set_realpath($non_existent_file, TRUE); // 顯示錯(cuò)誤,如同路徑不能決定 echo set_realpath($non_existent_file, FALSE); // 輸出 '/path/to/non-exist-file.txt' $directory = '/etc/php5'; echo set_realpath($directory); // 輸出 '/etc/php5/' $non_existent_directory = '/path/to/nowhere'; echo set_realpath($non_existent_directory, TRUE); // 顯示錯(cuò)誤,如同路徑不能決定 echo set_realpath($non_existent_directory, FALSE); // 輸出 '/path/to/nowhere'