All pastes #2079615 Raw Edit

Miscellany

public php v1 · immutable
#2079615 ·published 2011-09-03 06:46 UTC
rendered paste body
  $options['key'] = in_array($options['key'], array('uri', 'filename', 'name')) ? $options['key'] : 'uri';  $files = array();  if (is_dir($dir) && $handle = opendir($dir)) {    while (FALSE !== ($filename = readdir($handle))) {      if (!preg_match($options['nomask'], $filename) && $filename[0] != '.') {        $uri = "$dir/$filename";        $uri = file_stream_wrapper_uri_normalize($uri);        if (is_dir($uri) && $options['recurse']) {          // Give priority to files in this folder by merging them in after any subdirectory files.          $files = array_merge(file_scan_directory($uri, $mask, $options, $depth + 1), $files);        }        elseif ($depth >= $options['min_depth'] && preg_match($mask, $filename)) {          // Always use this match over anything already set in $files with the          // same $$options['key'].          $file = new stdClass();          $file->uri = $uri;          $file->filename = $filename;          $file->name = pathinfo($filename, PATHINFO_FILENAME);          $key = $options['key'];          $files[$file->$key] = $file;          if ($options['callback']) {            $options['callback']($uri);          }        }      }    }