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
The is_writable
function has only one mandatory parameter. This parameter is file
, which is the name of the file you wish to check.
The is_writable
function returns TRUE if you can write successfully to a file or the error E_WARNING
otherwise.
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