(PHP 4, PHP 5, PHP 7, PHP 8)
is_writable — 判斷給定的文件名是否可寫(xiě)
$filename
): bool
如果文件存在并且可寫(xiě)則返回 true
。filename
參數可以是一個(gè)允許進(jìn)行是否可寫(xiě)檢查的目錄名。
記住 PHP 也許只能以運行 webserver 的用戶(hù)名(通常為 'nobody')來(lái)訪(fǎng)問(wèn)文件。不計入安全模式的限制。
filename
要檢查的文件名稱(chēng)。
如果文件 filename
存在并且可寫(xiě)則返回 true
。
示例 #1 is_writable() 例子
<?php
$filename = 'test.txt';
if (is_writable($filename)) {
echo 'The file is writable';
} else {
echo 'The file is not writable';
}
?>
失敗時(shí)拋出E_WARNING
警告。
注意: 此函數的結果會(huì )被緩存。參見(jiàn) clearstatcache() 以獲得更多細節。
自 PHP 5.0.0 起, 此函數也用于某些 URL 包裝器。請參見(jiàn) 支持的協(xié)議和封裝協(xié)議以獲得支持 stat() 系列函數功能的包裝器列表。