Unfortunately, all answers are still erroneous or incomplete.
is_writable
Returns TRUE if the file name exists and is writable
It means that:
is_writable(__DIR__.'/file.txt');
Will return false, even if the script has write permissions to the directory, because file.txt does not yet exist.
, , :
is_writable(__DIR__);
, , , :
function isFileWritable($path)
{
$writable_file = (file_exists($path) && is_writable($path));
$writable_directory = (!file_exists($path) && is_writable(dirname($path)));
if ($writable_file || $writable_directory) {
return true;
}
return false;
}