is_writable
Checks whether a file or folder can be written to.
Syntax
is_writable(string $filename): boolParameters
| Parameter | Type | Description |
|---|---|---|
| $filename | string | The path to a file or folder. |
Return value
bool`true` if writing is allowed.
Examples
Can the temporary folder be written to:
<?php
var_dump(is_writable(sys_get_temp_dir()));Output:
bool(true)Notes
On a server the upload and cache folders must be writable by the user PHP runs as.
See also
- is_readable — Checks that a file exists and can be read.
- file_put_contents — Writes data to a file.
- mkdir — Creates a folder.
Related recipes
In the tutorial
- Reading and writing files — Working with files in PHP — writing, reading, appending, reading line by line, checking existence and deleting.