Advertisement
cafreak

Get Rekt scandir()

Dec 20th, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 KB | None | 0 0
  1. <?php
  2.    
  3.     if(!defined('_SCAN_TYPE_ALL_')){
  4.         DEFINE('_SCAN_TYPE_ALL_', 1);
  5.     }
  6.     if(!defined('_SCAN_TYPE_FILES_')){
  7.         DEFINE('_SCAN_TYPE_FILES_', 2);
  8.     }
  9.     if(!defined('_SCAN_TYPE_DIRS_')){
  10.         DEFINE('_SCAN_TYPE_DIRS_', 3);
  11.     }
  12.     function scan_dir($directory, $scan_type = _SCAN_TYPE_ALL_ ){
  13.         $scan = scandir($directory);
  14.         switch($scan_type){
  15.             case _SCAN_TYPE_ALL_ :
  16.                 return $scan;
  17.                 break;
  18.             case _SCAN_TYPE_DIRS_ :
  19.                 $directories = Array();
  20.                 foreach($scan as $dirname){
  21.                     if(is_dir($dirname)){
  22.                         $directories[] = $dirname;
  23.                     }
  24.                 }
  25.                 unset($scan);
  26.                 return $directories;
  27.                 break;
  28.             case _SCAN_TYPE_FILES_ :
  29.                 $files = Array();
  30.                 foreach($scan as $filename){
  31.                     if(is_file($filename)){
  32.                         $files[] = $filename;
  33.                     }
  34.                 }
  35.                 unset($scan);
  36.                 return $files;
  37.         }
  38.     }
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement