EKsparky Posted February 23, 2008 Share Posted February 23, 2008 Ive search and read for hours but no luck All i want to be able to do is list the directories (folders) within a certain dir(folder) Ive tried lots of differnt code but nothing works I found lots of code that will display both files and folders but i want just the folders. Example of code that work but displays both <?php if ($handle = opendir('galleries/')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { echo "$file\n"; } } closedir($handle); } ?> <?php Thanks for any help Quote Link to comment Share on other sites More sharing options...
fooDigi Posted February 23, 2008 Share Posted February 23, 2008 try this... <?php if ($handle = opendir('galleries/')) { while (false !== ($file = readdir($handle))) { if (is_dir($file)) { echo "$file\n"; } } closedir($handle); } ?> Quote Link to comment Share on other sites More sharing options...
fooDigi Posted February 23, 2008 Share Posted February 23, 2008 is_dir must be full path to file.... is_dir('/path/to/file/'.$file) Quote Link to comment Share on other sites More sharing options...
EKsparky Posted February 23, 2008 Author Share Posted February 23, 2008 Thanks i tried but still no luck The code i posted produced this out put Crewkerne _info.txt index.php Chard test Ilminster awards 031.jpg Your code produced . .. Quote Link to comment Share on other sites More sharing options...
fooDigi Posted February 23, 2008 Share Posted February 23, 2008 read my last post Quote Link to comment Share on other sites More sharing options...
fooDigi Posted February 23, 2008 Share Posted February 23, 2008 or you could use.... <?php if (filetype('/path/to/file/'.$file) == 'dir' && $file != "." && $file != "..") ?> sorry, you want to keep in ($file != "." && $file != "..") Quote Link to comment Share on other sites More sharing options...
EKsparky Posted February 23, 2008 Author Share Posted February 23, 2008 lol You replyed at same time as me Anyways i would not have thought id need the complete full path ie my script is in var/www/html/tkd4kids/public_html/photos so if i run it from there i assumed my path would just be just galleries/ I tried it with full path of var/www/html/tkd4kids/public_html/photos/galleries/ but no luck this result was empty not even . .. Quote Link to comment Share on other sites More sharing options...
EKsparky Posted February 23, 2008 Author Share Posted February 23, 2008 lol and again Quote Link to comment Share on other sites More sharing options...
fooDigi Posted February 23, 2008 Share Posted February 23, 2008 don;t know if it is a mispeling but, include the beginning forward slash... /var.... Quote Link to comment Share on other sites More sharing options...
EKsparky Posted February 23, 2008 Author Share Posted February 23, 2008 yes i did try both Quote Link to comment Share on other sites More sharing options...
fooDigi Posted February 23, 2008 Share Posted February 23, 2008 here is my complete working script, maybe this will help... <?php if ($handle = opendir('galleries/')) { while (false !== ($file = readdir($handle))) { if (is_dir('/home/xxxxx/public_html/_tests/galleries/'.$file) && $file != "." && $file != "..") { echo "$file\n"; } } closedir($handle); } ?> where does the script exist? Quote Link to comment Share on other sites More sharing options...
fooDigi Posted February 23, 2008 Share Posted February 23, 2008 or the following works also... try giving an absolute or root path to the opendir... <?php if ($handle = opendir('galleries/')) { while (false !== ($file = readdir($handle))) { if (filetype('/home/xxxxx/public_html/_tests/galleries/'.$file) == 'dir' && $file != "." && $file != "..") { echo "$file\n"; } } closedir($handle); } ?> Quote Link to comment Share on other sites More sharing options...
EKsparky Posted February 23, 2008 Author Share Posted February 23, 2008 Thanks for your help fooDigi That works I still can t see how the full path makes so much differnts when my origianl code did work but showed files as well Any ways its done Got up this morning with the intention of doing admin area for my gallery my php is not great so i started with the easiest tast and a that has taken all day lol Quote Link to comment Share on other sites More sharing options...
fooDigi Posted February 23, 2008 Share Posted February 23, 2008 the functions require that you have the complete path or correct relative path, from their perspective, they need to know where you are in the file system. you were just parsing the filename i believe. good luck with your admin area *edit - sorry i said they need to be complete paths, which is not true. you can use relative paths. sorry dude. i guess im on some kinda high horse Quote Link to comment Share on other sites More sharing options...
EKsparky Posted February 23, 2008 Author Share Posted February 23, 2008 I had to have a play as like i said it work b4 without full path and i managed to edit your script just a bit to get it work with out full path Assuming that the script is in /photos (full path var/www/html/tkd4kids/public_html/photos/galleries/) $dirname = "galleries/"; if ($handle = opendir($dirname)) { while (false !== ($file = readdir($handle))) { if (is_dir($dirname.$file) && $file != "." && $file != "..") { echo "$file\n"; } } closedir($handle); } ?> But again thanks for all your help 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.