Distinguish file and directory in PHP

Mar 12, 2012   //   by phpfreelancer.biz   //   Blog, PHP Tutorial  //  No Comments

You can use is_dir() or is_file() to check this and than use recursive functions to read those as well. or you can follow the below

$oIterator = new DirectoryIterator(dirname(__FILE__));
foreach ($oIterator as $oFileInfo) {

    // Either . or ..
    if ($oFileinfo->isDot()) {

    }

    // A directory
    if ($oFileInfo->isDir()) {

    }
}

Leave a comment

Share This Post

RSS Wordpress News