The is_writable() function checks whether a file is writeable. It returns TRUE if the file exists and is writeable.
Syntax
is_writable(file_path)
Parameters
file_path − The path of the file to be checked.
Return
The is_writable() function returns TRUE if the file exists and is writeable.
Example
<?php
$file = "one.txt";
if(is_writable($file)) {
echo ("File is writeable!");
} else {
echo ("File is not writeable!");
}
?>Output
File is not writeable!
Let us see another example.
Example
<?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”);
}
?>Output
File is writeable! Permission: 0777