Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
引数で指定したパスがディレクトリかのtrue/falseを返すPHPのユーザー関数
<?php
/*
========================================================================
指定したパスがディレクトリか否かをBOOLEANで返す (2種類)
https://gist.githubusercontent.com/KEINOS/b12a889ea822255d0156134da02f3a4a/raw/function.dir_exists.php
========================================================================
*/
/**
* dir_exists function. (Type A)
*
* is_dir()の語感互換関数
*
* @access public
* @param string $path_dir
* @return bool
*/
if (! function_exists('dir_exists')) {
function dir_exists($path_dir)
{
return is_dir((string) $path_dir);
}
}
/**
* dir_exists function. (Type B)
*
* is_dir()の語感互換関数
*
* @access public
* @param string $path_dir
* @return bool
*/
if (! function_exists('dir_exists')) {
function dir_exists($dir_name = false)
{
if (! $dir_name) {
return false;
}
$dir_name = realpath(trim($dir_name));
if (file_exists($dir_name)) {
return ( is_dir($dir_name) ) ? true : false;
} else {
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.