note 100805 added to function.readdir

From: Date: Mon, 08 Nov 2010 12:07:42 +0000
Subject: note 100805 added to function.readdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-173844@lists.php.net to get a copy of this message
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( "." ); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 85.240.130.224 ---- Manual Page -- http://www.php.net/manual/en/function.readdir.php Edit -- https://master.php.net/note/edit/100805 Del: integrated -- https://master.php.net/note/delete/100805/integrated Del: useless -- https://master.php.net/note/delete/100805/useless Del: bad code -- https://master.php.net/note/delete/100805/bad+code Del: spam -- https://master.php.net/note/delete/100805/spam Del: non-english -- https://master.php.net/note/delete/100805/non-english Del: in docs -- https://master.php.net/note/delete/100805/in+docs Del: other reasons-- https://master.php.net/note/delete/100805 Reject -- https://master.php.net/note/reject/100805 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#173844) next »