NeverPool Posted April 21, 2010 Share Posted April 21, 2010 Hullo, I wrote this script for my website and I can't figure out how I can exclude directories and files from it. http://test.neverpool.com/sitemap.php Here's the code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Directory Contents</title> <style type="text/css"> a:link {color:#000000;} /* unvisited link */ a:visited {color:#FF0000;} /* visited link */ a:hover {color:#000099;} /* mouse over link */ a:active {color:#FF0000;} /* selected link */ </style> </head> <body> <?php /* This script is copyrighted by NeverPool.com if you have any questions, email me. Creechl84@gmail.com. COPYRIGHT 2009-2010 */ $dir = '.'; $dateformat = 'F j, Y'; $file = glob($dir . '/*'); $dirs = array(); $files = array(); foreach ($file as $f) { if (is_dir($f)) $dirs[] = $f; else $files[] = $f; } echo '<ul>'; foreach ($dirs as $d) { $base = basename($d); echo "<li><a href=\"$base\">$base</a>"; } echo '</ul>'; echo '<table>'; echo '<thead><tr><th>Name<th>Size<th>Last Modified'; echo '<tbody>'; foreach ($files as $f) { $base = basename($f); $size = number_format(filesize($f)); $date = date($dateformat, filemtime($f)); echo "<tr><td><a href=\"$base\">$base</a><td>$size bytes<td>$date"; } echo '</table>'; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/199305-i-need-to-exclude-files-and-directories/ Share on other sites More sharing options...
premiso Posted April 21, 2010 Share Posted April 21, 2010 One way, create an array of "Excluded directories" and an array of "excluded files" then use the in_array function before printing or assigning them to anything, if they are NOT in the excluded array, print / assign them. If they are continue onward and do not process them. Quote Link to comment https://forums.phpfreaks.com/topic/199305-i-need-to-exclude-files-and-directories/#findComment-1046041 Share on other sites More sharing options...
NeverPool Posted April 21, 2010 Author Share Posted April 21, 2010 One way, create an array of "Excluded directories" and an array of "excluded files" then use the in_array function before printing or assigning them to anything, if they are NOT in the excluded array, print / assign them. If they are continue onward and do not process them. I appreciate the fast response, I'll get on it . Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/199305-i-need-to-exclude-files-and-directories/#findComment-1046045 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.