Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old December 20th, 2005, 12:04 PM
Registered User
Join Date: Dec 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to hillbilly geek
Default creating a list of folders

This is my first post: I'll be working my way through Beginning php4
but a quick question that's been bugging me:

Say I have a number of folders inside a folder: can php return me those folder names as an array, or a list, similar to the way it traverses a file like:

    $handle = fopen("$folder/pics.txt", "r");
    while ($line = fgets ($handle,4096)) {
         list ($picfile, $picname, $picprice, $picdescrip ) = explode ("|", $line);

I'd like to be able to look in a folder and create a pulldown navigation menu.
Also, is there a way to have it ignore file names and just get the folder names?
Old December 28th, 2005, 09:32 AM
Friend of Wrox
Join Date: Dec 2004
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts

I don't use that system @ all.

To be honnest it took me ages to get the code bellow to work; I had to strip bits of code from answers on this forum and bit of code on the internet; but the code I use works great for me!!

Perhaps you can adapt it to only list folder:


if ($handle = opendir('../mp3')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
        if (substr($file, strlen($file)-3, 3)=="mp3" ) {
            $FileArray[] = $file;


Good luck ^^

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a list of users DennyLoi Javascript How-To 0 November 9th, 2007 04:32 AM
Creating a list depending on a tag value josephine XSLT 1 October 26th, 2007 05:39 AM
Problems with creating folders kuznickic VBScript 0 August 13th, 2007 03:26 PM
Creating folders on network share JonniP Access VBA 1 January 3rd, 2007 03:51 PM
creating dynamic list fyeojo VS.NET 2002/2003 4 September 2nd, 2003 03:13 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.