Last active
August 26, 2017 12:47
-
-
Save jasondmoss/7344322 to your computer and use it in GitHub Desktop.
Is file writable? If not try to to make it so...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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