patchido Posted October 3, 2011 Share Posted October 3, 2011 i am getting this as a echo, Directory handle: Resource id #2 Files: . .. why? <? if ($handle = opendir('images')) { echo "Directory handle: $handle\n"; echo "Files:\n"; /* This is the correct way to loop over the directory. */ while (false !== ($file = readdir($handle))){ if (is_dir($file)){ echo "$file\n"; } } closedir($handle); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/248354-read-directories-inside-a-directory/ Share on other sites More sharing options...
requinix Posted October 3, 2011 Share Posted October 3, 2011 Because $handle is a resource. Maybe you don't understand how those functions work? Quote Link to comment https://forums.phpfreaks.com/topic/248354-read-directories-inside-a-directory/#findComment-1275361 Share on other sites More sharing options...
patchido Posted October 3, 2011 Author Share Posted October 3, 2011 ok, so how would i do to echo every directory inside that directory? Quote Link to comment https://forums.phpfreaks.com/topic/248354-read-directories-inside-a-directory/#findComment-1275366 Share on other sites More sharing options...
AbraCadaver Posted October 3, 2011 Share Posted October 3, 2011 I prefer glob: foreach(glob('images/*', GLOB_ONLYDIR) as $dir) { echo $dir; } Quote Link to comment https://forums.phpfreaks.com/topic/248354-read-directories-inside-a-directory/#findComment-1275371 Share on other sites More sharing options...
patchido Posted October 3, 2011 Author Share Posted October 3, 2011 thank you! that works as a charm, after that ill just strip out the first part of the path thx Quote Link to comment https://forums.phpfreaks.com/topic/248354-read-directories-inside-a-directory/#findComment-1275372 Share on other sites More sharing options...
AbraCadaver Posted October 3, 2011 Share Posted October 3, 2011 thank you! that works as a charm, after that ill just strip out the first part of the path thanks basename() foreach(glob('images/*', GLOB_ONLYDIR) as $dir) { echo basename($dir); } Quote Link to comment https://forums.phpfreaks.com/topic/248354-read-directories-inside-a-directory/#findComment-1275414 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.