268 of 410 menu

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

is_writable(filename);

Example

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

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

Code execution result:

true

Example

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

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

Code execution result:

false

Example

Let's check the writability of a directory:

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

Code execution result:

true

See Also

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