hello, i have a space where we discuss and upload files many times a day.Its quite hard for me to update html page with links to all files soo i currently deleted index.html so all can view the files on server is there anyway an html or PHP file show up files on refresh because it is quite odd to look at files from the root HELP!!!!! ! thanks
<?php $handle = opendir( 'directorywithfiles' ); while( $file = readdir( $handle ) ): if( $file != "." and $file != ".." ) { printf( 'Filename : %s<br />', $file ); } endwhile; closedir( $handle ); PHP:
You asked me a question via pm, which I'll answer here for everyones enjoyment. You asked if you could block certain files from being shown, there are a few decent ways of doing this, here they are : Way 1 : we'll create an array of disallowed files and check them as we loop over directory contents <? $disallowed = array ( 'secret.php', 'mine.php', 'noshow.php' ); $handle = opendir( "I:/xampp/xampp/htdocs" ); while( $file = readdir( $handle )): if(!in_array( $file, $disallowed ) and $file != "." and $file != ".." and !is_dir( $file ) ) { printf( "Filename : %s<br />\n", $file ); } endwhile; closedir($handle); ?> PHP: Way 2 : We'll match the filenames with a pattern <? $pattern = '#\.html$#si'; $handle = opendir( "I:/xampp/xampp/htdocs" ); while( $file = readdir( $handle )): if( preg_match( $pattern, $file ) and $file != "." and $file != ".." and !is_dir( $file ) ) { printf( "Filename : %s<br />\n", $file ); } endwhile; ?> PHP: Way 3 : We'll match the filenames by an extension <? $ext = ".php"; $handle = opendir( "I:/xampp/xampp/htdocs" ); while( $file = readdir( $handle )): if( substr( $file, strlen( $file ) - strlen( $ext ) ) == $ext and $file != "." and $file != ".." and !is_dir( $file ) ) { printf( "Filename : %s<br />\n", $file ); } endwhile; ?> PHP: There are probably more but one of those is bound to suit your purpose, all these example do not read directories as files