What is the is_writable() function in PHP?

Overview

The is_writable function in PHP is used to check whether a file can be written to. The general syntax for the is_writable function is as follows:

is_writable(string $filename): bool

Parameter

The is_writable function has only one mandatory parameter. This parameter is file, which is the name of the file you wish to check.

Return value

The is_writable function returns TRUE if you can write successfully to a file or the error E_WARNING otherwise.

Example

The following example will help you understand the is_writable function. As shown, the is_writable function takes the file main.txt as input and returns false. This means we cannot write to the file main.txt because it does not exist.

<?php
$file = "main.txt";
if(is_writable($file)) {
echo ("You can write to the file");
} else {
echo ("You cannot write to the file");
}
?>

Free Resources

Copyright ©2026 Educative, Inc. All rights reserved