Paste: Util Class with pathCheck method
Author: | hirojin |
Mode: | php |
Date: | Sun, 22 Jan 2012 22:42:30 |
Plain Text |
/**
* Checks a file or directory existence and readability
*
* @param string $path /path/to/dir/or/file
* @param string $fd Either 'f' for file or 'd' for directory.
* @param string $rw Either 'w' for a check on writability or 'r' for a check on readability.
*
* @return bool
*/
public static function checkPath (
$path,
$fd,
$rw )
{
if ( $fd == 'f') {
if (is_file($path) != true) {
Log::debug ( $path . ' is not a file');
return false;
}
} elseif ( $fd == 'd') {
if (is_dir($path) != true) {
Log::debug ( $path . ' is not a directory');
return false;
}
} else {
Log::debug ( '$fd must be either "f" or "d"');
return false;
}
if ( $rw == 'r') {
if (!is_readable($path)) {
Log::debug ( $path . ' is not a readable');
return false;
}
} elseif ( $rw == 'w') {
if (!is_writable($path)) {
Log::debug ( $path . ' is not a writable');
return false;
}
} elseif ( $rw == 'rw' ) {
if (!is_readable($path) || !is_writable($path)) {
Log::debug ( $path . ' is not a writable and readable.');
return false;
}
} else {
Log::debug ( '$rw must be either "r" or "w"');
return false;
}
return true;
}
New Annotation