jonw118 Posted December 14, 2010 Share Posted December 14, 2010 I am using the following php script to display all the files that are uploaded in a directory on a page. There are two files in the folder I do not want displayed: .htaccess & index.php. Can someone help me out and provide a little guidance about what I need to do to print all the file names EXCEPT for those two. I imagine some sort of if statement. CODE: Top of page: <?php $dirname = "."; $dir = opendir($dirname); ?> Body: <?php while(false != ($file = readdir($dir))) { if(($file != ".") and ($file != "..")) { echo("<a href='$dirname$file'>$file</a> <br />"); } } ?> Thanks so much! Quote Link to comment Share on other sites More sharing options...
BK87 Posted December 14, 2010 Share Posted December 14, 2010 <?php while(false != ($file = readdir($dir))) { if($file != "." && $file != ".." && $file!=".htaccess"&&$file!="index.php") { echo("<a href='$dirname$file'>$file</a> <br />"); } } ?> Quote Link to comment Share on other sites More sharing options...
MMDE Posted December 14, 2010 Share Posted December 14, 2010 if($handle = opendir('.')){ while(false !== ($file = readdir($handle))){ if($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess'){ echo '<br /> <a href="'.$file.'">'.$file.'</a>'; } } closedir($handle); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.