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! Link to comment https://forums.phpfreaks.com/topic/221575-if-statement-to-remove-file-name-from-displaying-in-php-list/ 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 />"); } } ?> Link to comment https://forums.phpfreaks.com/topic/221575-if-statement-to-remove-file-name-from-displaying-in-php-list/#findComment-1146977 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); } Link to comment https://forums.phpfreaks.com/topic/221575-if-statement-to-remove-file-name-from-displaying-in-php-list/#findComment-1146979 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.