PHP » I/O » is_writable()

Syntax:
bool is_writeable(string filename)
filename
The name of the file to check.

Returns whether a file is writable.

This function returns TRUE if PHP has write access to a specified file and FALSE if it does not. If the file does not exist FALSE is also returned.

Examples

Code:
<?php

$filename = "log.txt";

if (is_writable($filename)) {
   print "File is writable";
   $logfile = fopen($filename, "a");
} else {
   print "Write access denied to $filename, or file does not exist!";
}

?>
Output:
Write access denied to log.txt, or file does not exist!
Explanation:

If the file does not exist, or user privileges of PHP do not permit writing to the file, is_writable() will return FALSE.

See Also: