Skip to content

Instantly share code, notes, and snippets.

@jasondmoss
Last active August 26, 2017 12:47
Show Gist options
  • Save jasondmoss/7344322 to your computer and use it in GitHub Desktop.
Save jasondmoss/7344322 to your computer and use it in GitHub Desktop.
Is file writable? If not try to to make it so...
<?php
/**
* Check if a file/folder is writable. If not, the function tries to make
* it writable.
*
* @param string $file
* @param string $mode
*
* @return File
* @access public
*/
function isWritable($file, $mode = 'auto')
{
if (is_writable($file)) {
return true;
}
if ('auto' == $mode) {
$mode = 0644;
if (is_dir($file)) {
$mode = 0755;
}
}
return @chmod($file, $mode);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment