AbydosGater Posted May 6, 2007 Share Posted May 6, 2007 Hey, Im working on a module system for my site and i want to load all the files in a directory. Im doing this with ... <?php $dp = 'modules/' . $module; $dh = opendir($dp); while ($file = readdir($dh)){ $files[] = $file; } foreach ($files as $key => $file){ echo $file . '<br />'; } ?> But that is returning the following.. . .. mymodulesinfo.xml mymodule.php why is it pulling the . and ..? Is this just always done by readdir? and if so do i just count the foreach to only echo the $key's that are valued 2 or over? Any help is greatly appriciated. Andy Quote Link to comment https://forums.phpfreaks.com/topic/50241-listing-all-the-files-in-a-directory-not-working-really/ Share on other sites More sharing options...
neel_basu Posted May 6, 2007 Share Posted May 6, 2007 why is it pulling the . and ..?"." and ".." Means the mother Directories. Quote Link to comment https://forums.phpfreaks.com/topic/50241-listing-all-the-files-in-a-directory-not-working-really/#findComment-246598 Share on other sites More sharing options...
AbydosGater Posted May 6, 2007 Author Share Posted May 6, 2007 Yeah i know that but i only want it to pull the files, not other directories. Could i solve this with. <?php <?php $dp = 'modules/' . $module; $dh = opendir($dp); while ($file = readdir($dh)){ $files[] = $file; } foreach ($files as $key => $file){ if ($key >= 2) echo $file; } ?> ?> That way it would skip the mother directorys? Quote Link to comment https://forums.phpfreaks.com/topic/50241-listing-all-the-files-in-a-directory-not-working-really/#findComment-246602 Share on other sites More sharing options...
neel_basu Posted May 6, 2007 Share Posted May 6, 2007 Use if(is_file('modules/'.$file)) { echo $file; } Quote Link to comment https://forums.phpfreaks.com/topic/50241-listing-all-the-files-in-a-directory-not-working-really/#findComment-246610 Share on other sites More sharing options...
AbydosGater Posted May 6, 2007 Author Share Posted May 6, 2007 Oh great, working brill! Thanks! Andy Quote Link to comment https://forums.phpfreaks.com/topic/50241-listing-all-the-files-in-a-directory-not-working-really/#findComment-246621 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.