PHP 中的 is_writable() 函数
phpprogrammingserver side programming更新于 2025/7/9 12:37:17
is_writable() 函数检查文件是否可写。如果文件存在且可写,则返回 TRUE。
语法
is_writable(file_path)
参数
file_path − 待检查文件的路径。
返回值
如果文件存在且可写,is_writable() 函数返回 TRUE。
示例
<?php
$file = "one.txt";
if(is_writable($file)) {
echo ("File is writeable!");
} else {
echo ("File is not writeable!");
}
?>
输出
File is not writeable!
让我们看另一个例子。
示例
<?php
$file_permissions = fileperms("two.txt");
$res = sprintf("%o", $file_permissions);
$file = "two.txt";
if(is_writable($file)) {
echo ("File is writeable!");
echo(“Permission = $res”);
} else {
echo ("File is not writeable!");
echo(“Permission = $res”);
}
?>
输出
File is writeable! Permission: 0777

