(PHP 4, PHP 5)
is_readable — 判斷給定文件名是否可讀
說明
bool is_readable ( string$filename
)
判斷給定文件名是否存在并且可讀。
參數(shù)
filename
文件的路徑。
返回值
如果由 filename
指定的文件或目錄存在并且可讀則返回 TRUE
,否則返回 FALSE
。
范例
Example #1 is_readable() 例子
<?php
$filename = 'test.txt';
if (is_readable($filename)) {
echo 'The file is readable';
} else {
echo 'The file is not readable';
}
?>
錯(cuò)誤/異常
失敗時(shí)拋出E_WARNING
警告。
注釋
記住 PHP 也許只能以運(yùn)行 webserver 的用戶名(通常為 'nobody')來訪問文件。不計(jì)入安全模式的限制。 Safe mode limitations are not taken into account before PHP 5.1.5.
Note: 此函數(shù)的結(jié)果會(huì)被緩存。參見 clearstatcache() 以獲得更多細(xì)節(jié)。
Tip自 PHP 5.0.0 起, 此函數(shù)也用于某些 URL 包裝器。請(qǐng)參見 支持的協(xié)議和封裝協(xié)議以獲得支持 stat() 系列函數(shù)功能的包裝器列表。
Note:
The check is done using the real UID/GID instead of the effective one.
對(duì)于目錄這個(gè)函數(shù)可能會(huì)返回 TRUE
。請(qǐng)使用 is_dir() 來區(qū)分文件和目錄。
參見
is_writable() - 判斷給定的文件名是否可寫 file_exists() - 檢查文件或目錄是否存在 fgets() - 從文件指針中讀取一行