note 100805 deleted from function.readdir by danbrown

From: Date: Mon, 08 Nov 2010 17:45:19 +0000
Subject: note 100805 deleted from function.readdir by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-173863@lists.php.net to get a copy of this message
Note Submitter: goulart dot g at gmail dot com ---- This script reads dirs inside dirs, and can pass a variable with the full path of the file the system is reading so it can open it, and checkFilename function will check if the filename is in lowercase and if the file is in UTF-8 or not... <?php /* * Script Developed by * Ricardo Goulart * @ CleverTI * 2010-11-04 */ function checkFilename ( $checkFilename_FILENAME = NULL , $checkFilename_SPACES = 0 , $dir ) { //When cheking for UTF-8 encoding, search also on theese extensions: $extensions = array ( "php" , "ini" , "txt" , "css" , "html" , "htm" , "js" ); if ( $checkFilename_FILENAME ) { if ( strcmp ( $checkFilename_FILENAME , strtolower ( $checkFilename_FILENAME ) ) ) { if ( in_array ( array_pop ( explode ( '.' , $checkFilename_FILENAME ) ) , $extensions ) ) { if ( mb_detect_encoding ( file_get_contents ( $dir->path . $checkFilename_FILENAME ) , "auto") !== "UTF-8" ) { return "$checkFilename_SPACES<span style='color:#9900FF;'>$checkFilename_FILENAME</span><br />"; } else { return "$checkFilename_SPACES<span style='color:#FF9900;'>$checkFilename_FILENAME</span><br />"; } } else { return "$checkFilename_SPACES<span style='color:#FF9900;'>$checkFilename_FILENAME</span><br />"; } } else { if ( in_array ( array_pop ( explode ( '.' , $checkFilename_FILENAME ) ) , $extensions ) ) { if ( mb_detect_encoding( file_get_contents ( $dir->path . $checkFilename_FILENAME ) , "auto" ) !== "UTF-8" ) { return "$checkFilename_SPACES<span style='color:#9900FF;'>$checkFilename_FILENAME</span><br />"; } else { return "$checkFilename_SPACES $checkFilename_FILENAME <br />"; } } else { return "$checkFilename_SPACES $checkFilename_FILENAME <br />"; } } } else { return false; } } function getDirectory( $path = '.', $level = 0 ) { $ignore = array( 'cgi-bin', '.', '..' ); $dh = @opendir( $path ); while( false !== ( $file = readdir( $dh ) ) ) { if( !in_array( $file, $ignore ) ) { $spaces = str_repeat( '&nbsp;', ( $level * 4 ) ); if( is_dir( "$path/$file" ) ) { echo "<strong>$spaces $file</strong><br />"; getDirectory( "$path/$file", ( $level+1 ) ); } else { echo checkFilename( $file , $spaces , dir ($path."/") ); } } } closedir( $dh ); } getDirectory( "." ); ?>

« previous php.notes (#173863) next »