The is_writable Function

The is_writable function checks whether the specified file or directory exists and is writable. It takes the path to the file or directory as a parameter. The function returns true if writing is possible, and false otherwise.

Syntax

phpis_writable(filename);

Example

Let's check if the file 'test.txt' is writable:

php<?php
  $res = is_writable('test.txt');
  var_dump($res);
?>

Code execution result:

phptrue

Example

Let's check the accessibility of a non-existent file:

php<?php
  $res = is_writable('nonexistent.txt');
  var_dump($res);
?>

Code execution result:

phpfalse

Example

Let's check the writability of a directory:

php<?php
  $res = is_writable('/path/to/directory');
  var_dump($res);
?>

Code execution result:

phptrue

See Also

  • the is_readable function,
    which checks readability
  • the is_executable function,
    which checks executability
  • the chmod function,
    which changes access permissions