is_writable

(PHP 4, PHP 5, PHP 7, PHP 8)

is_writable判断给定的文件名是否可写

说明

is_writable(string $filename): bool

如果文件存在并且可写则返回 truefilename 参数可以是一个允许进行是否可写检查的目录名。

记住 PHP 也许只能以运行 webserver 的用户名(通常为 'nobody')来访问文件。

参数

filename

要检查的文件名称。

返回值

如果文件 filename 存在并且可写则返回 true

错误/异常

失败时抛出 E_WARNING 警告。

范例

示例 #1 is_writable() 例子

<?php
$filename
= 'test.txt';
if (
is_writable($filename)) {
echo
'The file is writable';
} else {
echo
'The file is not writable';
}
?>

注释

注意: 此函数的结果会被缓存。参见 clearstatcache() 以获得更多细节。

小技巧

自 PHP 5.0.0 起, 此函数也用于某些 URL 包装器。请参见 支持的协议和封装协议以获得支持 stat() 系列函数功能的包装器列表。

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top