Skip to content

Instantly share code, notes, and snippets.

@KEINOS
Last active February 8, 2018 08:25
Show Gist options
  • Select an option

  • Save KEINOS/b12a889ea822255d0156134da02f3a4a to your computer and use it in GitHub Desktop.

Select an option

Save KEINOS/b12a889ea822255d0156134da02f3a4a to your computer and use it in GitHub Desktop.
引数で指定したパスがディレクトリかの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