i came across few articles about performance and readdir here is the php script:
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( ' ', ( $level * 4 ) );
if( is_dir( "$path/$file" ) ){
echo "$spaces $file\n";
getDirectory( "$path/$file", ($level+1) );
} else {
echo "$spaces $file\n";
}
}
}
closedir( $dh );
}
getDirectory( "." );
this echo the files/ folders correctly.
now i found this:
$t = system('find');
print_r($t);
which also find all the folders and files then i can create an array like the first code.
i think the system('find');
is faster than the readdir
but i want to know if it'S a good practice?
thank you very much
system()
calls. They should be fine without parameters, but if you construct them dynamically based on user input, you're likely to create bad security holes. – Futch