Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function fast_cat( $path = '', $ext = array() )
- {
- global $nen;
- if( is_string( $ext ) )
- {
- $ext = array( 0 => $ext );
- }
- if( ( !is_array( $ext ) ) | ( $ext === array() ) )
- {
- $ext = array( 0 => '' );
- }
- $buffer = ( is_dir( $_SERVER[ 'DOCUMENT_ROOT' ] . '/' . $path ) ? array_diff( scandir( $_SERVER[ 'DOCUMENT_ROOT' ] . '/' . $path, SCANDIR_SORT_ASCENDING ), array( '..', '.' ) ) : array() );
- $cat = array();
- foreach( $buffer as $entry )
- {
- $hit = 0;
- foreach( $ext as $test )
- {
- if( strtolower( substr( $entry, -strlen( $test ), strlen( $test ) ) ) === strtolower( $test ) )
- {
- $hit++;
- break;
- }
- }
- if( $hit > 0 )
- {
- $cat[ count( $cat ) ] = $entry;
- }
- }
- natcasesort( $cat );
- $cat = array_values( $cat );
- return $cat;
- }
- function cat_rando( $cat )
- {
- global $nen;
- if( count( $cat ) > 0 )
- {
- return $cat[ rand( 0, count( $cat ) - 1 ) ];
- }
- else
- {
- return '';
- }
- }
- function fast_cat_ii( $path = '', $ext = array(), $type = __FILE__ )
- {
- if( !is_array( $ext ) )
- {
- $ext = array( $ext );
- }
- $cat = array();
- $iterator = new DirectoryIterator( dirname( $type ) );
- while( $iterator -> valid() )
- {
- $test = $iterator -> getFilename();
- foreach( $ext as $test_ext )
- {
- if( strtolower( substr( $test, -strlen( $ext ) ) ) === strtolower( $test_ext ) )
- {
- $cat[] = $test;
- break;
- }
- }
- $iterator -> next();
- }
- return $cat;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement