In PHP, is_writeable() checks whether a file or folder exists and can be written to. It is an alias of is_writable(), so both names do exactly the same thing.
Use it before saving data, so your script can show a friendly message instead of a warning when the file is locked or has the wrong permissions.
Syntax
Call is_writeable() with the values you need. Start with this line.
PHP
$canWrite = is_writeable('logs/app.log');
Call
What it does
is_writeable('notes.txt')
Returns true if notes.txt exists and your script is allowed to change it.
is_writeable(__DIR__)
Checks whether the current folder accepts new files.
is_writeable('missing.txt')
Returns false because the file does not exist.
is_writeable() is only an alias. Most tutorials and the official manual use the spelling is_writable(), so pick one name and use it everywhere in your project. The result is cached by PHP for the same path, so call clearstatcache() if you change permissions during the same request.
Library declarations
PHP
is_writeable(string $filename): bool
Parameters
Parameter
Description
filename
Required. The path to the file or directory you want to test.
Return Value
Return Value
Description
bool
Returns true if the path exists and is writable, otherwise false.
PHP Examples
Example 1 — Check a File Before Editing
Create a small file and test whether PHP is allowed to change it.
PHP
<?php
$file = __DIR__ . '/notes.txt';
file_put_contents($file, 'Hello');
if (is_writeable($file)) {
echo "notes.txt can be edited", PHP_EOL;
} else {
echo "notes.txt is read only", PHP_EOL;
}
Output
notes.txt can be edited
How It Works
file_put_contents() creates notes. txt so the file really exists.
is_writeable() asks the system if the current user may write to it.
The file was just created by this script, so the answer is true.
The first message is printed.
Example 2 — Missing Files Are Not Writable
is_writeable() returns false when the path does not exist, even if the folder itself is writable.