AbydosGater Posted June 24, 2007 Share Posted June 24, 2007 Hi, Just working on a directory reading script..But the output is all messed up. Here is the code: <?php $dp = opendir("/apache2triad/"); $files = array(); $dirs = array(); $unknowns = array(); while (false !== ($file = readdir($dp))){ if (is_file($file)){ $files[] = $file; } elseif (is_dir($file)){ $dirs[] = $file; } else { $unknowns[] = $file; } } echo '<strong>Files:</strong><br />'; foreach ($files as $current){ echo $current.'<br />'; } echo '<br /><hr /><br />'; echo '<strong>Directorys:</strong><br />'; foreach ($dirs as $current){ echo $current.'<br />'; } echo '<br /><hr /><br />'; echo '<strong>Unknown Files:</strong><br />'; foreach ($unknowns as $current){ echo $current.'<br />'; } echo '<br /><hr /><br />'; ?> But All the basic files like the "htdocs" file and the directorys like "." and ".." and being saved right.. But everything else.. ALL other files and folders are being saved as unknowns... can anyone see what im doing wrong? Please? Thanks Andy Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted June 24, 2007 Share Posted June 24, 2007 When you use is_dir or is_file you will also want to define the path where those files/directory exists. If you don't define the path then it will look in the directory the script is being ran in. It wont check the directory you are reading. Try this: <?php define('DIR', '../Apache/'); $dp = opendir(DIR); $files = array(); $dirs = array(); $unknowns = array(); while (false !== ($file = readdir($dp))) { if (is_file(DIR . $file)) { $files[] = $file; } elseif (is_dir(DIR . $file)) { $dirs[] = $file; } else { $unknowns[] = $file; } } echo '<strong>Files:</strong><br />'; foreach ($files as $file) { echo $file.'<br />'; } echo '<br /><hr /><br />'; echo '<strong>Directorys:</strong><br />'; foreach ($dirs as $dir) { echo $dir.'<br />'; } echo '<br /><hr /><br />'; echo '<strong>Unknown Files:</strong><br />'; foreach ($unknowns as $unkown) { echo $unkown.'<br />'; } echo '<br /><hr /><br />'; ?> Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted June 24, 2007 Author Share Posted June 24, 2007 Yay! Thanks wildteen. All working now! Lol its always the small things i leave out that get me! Thanks! 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.