array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.is-writable.php', 1 => 'is_writable', ), 'up' => array ( 0 => 'ref.filesystem.php', 1 => '文件系统函数', ), 'prev' => array ( 0 => 'function.is-uploaded-file.php', 1 => 'is_uploaded_file', ), 'next' => array ( 0 => 'function.is-writeable.php', 1 => 'is_writeable', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/filesystem/functions/is-writable.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
is_writable — 判断给定的文件名是否可写
如果文件存在并且可写则返回 true
。filename
参数可以是一个允许进行是否可写检查的目录名。
记住 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() 系列函数功能的包装器列表。