PHP/File Directory/is writable
is_writable() tells you whether you can write to a file.
<source lang="html4strict">
<? if ( is_writable( "data.txt" ) ) {
print "data.txt is writable";
} ?>
</source>
is_writeable
<source lang="html4strict">
<?php $file_name="permissions.php"; if(is_writeable($file_name)) {
echo ("The file $file_name is writeable.
");
} else {
echo ("The file $file_name is not writeable.
");
} ?>
</source>
Testing for write permission
<source lang="html4strict">
$log_file = "/var/log/users.log"; if (is_writeable($log_file)) {
$fh = fopen($log_file,"ab"); fwrite($fh, $_SESSION["username"] . " at " . strftime("%c") . "\n"); fclose($fh);
} else {
print "Can"t write to log file.";
}
</source>