lorne17 Posted August 13, 2008 Share Posted August 13, 2008 Hello there, I'm new to PHP and i have set up a file to allow for the user to see a list of files in a specific directory. I used this code and it works great. No issues: <?php if ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $thelist .= '<a href="'.$file.'">'.$file.'</a>'.'<br>'; } } closedir($handle); } ?> <p style="font-weight: bold; font-size: 10pt">List of files:</p> <p style="font-weight: bold; font-size: 10pt; color: #560D1C"><?=$thelist?></p> Now what I want to do is specifically hide files that are in this directory. When the user looks at the list the files .htaccess, .htpsswd, index.php. The first two files are automatically created when I save index.php. So what I want is to hide those three including the index.php (take note that the page with this list is the index.php). Can anyone give suggestions?? Thanks, Lorne Quote Link to comment https://forums.phpfreaks.com/topic/119551-how-to-hide-file-extensions-using-handle-opendir/ Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 <?php if ($handle = opendir('.')) { $blacklist = array('.', '..', 'index.php', '.htaccess', '.htpswwd'); while (false !== ($file = readdir($handle))) { if (!in_array($file, $blacklist)) { $thelist .= '<a href="'.$file.'">'.$file.'</a>'.'<br>'; } } closedir($handle); } ?> <p style="font-weight: bold; font-size: 10pt">List of files:</p> <p style="font-weight: bold; font-size: 10pt; color: #560D1C"><?=$thelist?></p> Quote Link to comment https://forums.phpfreaks.com/topic/119551-how-to-hide-file-extensions-using-handle-opendir/#findComment-615891 Share on other sites More sharing options...
wildteen88 Posted August 13, 2008 Share Posted August 13, 2008 Change while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") to $ignore_files = array('.', '..', '.htaccess', '.htpsswd', 'index.php'); while (false !== ($file = readdir($handle))) { if (!in_array($file, $ignore_files)) EDIT: too slow ;)/b] Quote Link to comment https://forums.phpfreaks.com/topic/119551-how-to-hide-file-extensions-using-handle-opendir/#findComment-615892 Share on other sites More sharing options...
lorne17 Posted August 13, 2008 Author Share Posted August 13, 2008 That worked great, Thanks ...here's the final working code for reference... <?php if ($handle = opendir('.')) { $ignore_files = array('.', '..', '.htaccess', '.htpasswd', 'index.php'); while (false !== ($file = readdir($handle))) { if (!in_array($file, $ignore_files)) { $thelist .= '<a href="'.$file.'">'.$file.'</a>'.'<br>'; } } closedir($handle); } ?> <p style="font-weight: bold; font-size: 10pt">List of files:</p> <p style="font-weight: bold; font-size: 10pt; color: #560D1C"><?=$thelist?></p> Quote Link to comment https://forums.phpfreaks.com/topic/119551-how-to-hide-file-extensions-using-handle-opendir/#findComment-615955 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.