PHP/File Directory/is writable

Материал из Web эксперт
Перейти к: навигация, поиск

is_writable() tells you whether you can write to a file.

 
<?
if ( is_writable( "data.txt" ) ) {
  print "data.txt is writable";
}
?>



is_writeable

 
<?php
$file_name="permissions.php";
if(is_writeable($file_name)) {
    echo ("The file $file_name is writeable.<br />");
}
else {
    echo ("The file $file_name is not writeable.<br />");
}
?>



Testing for write permission

 
$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.";
}