A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: PHP - Read Nested Folders and Files

  1. #1
    Senior Member andrthad's Avatar
    Join Date
    Apr 2002
    Location
    Oklahoma - USA
    Posts
    154

    PHP - Read Nested Folders and Files

    Hi All,

    I am a PHP newbie. Say you have the following file structure:

    Counting Crows (artist)
    Hard Candy (album)
    Hard Candy.mp3 (song name)
    American Girls.mp3

    David Gray
    White Ladder
    Please Forgive Me.mp3
    White Ladder.mp3


    I need some suggestions on how to read this file structure either into an array or possibly just to update a MySQL database and then read the database. I will constantly be adding or subtracting files so I want to try and make it as dynamic as I can.

    Suggestions, comments, code?
    PC | 1.7GHz P4 | 256MB RAM | FLASH MX | IE6 | WIN XP | BROADBAND

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,039
    Hi,

    just a suggestion: if you have mysql available, use it....
    You can avoid one level of folders if you want, and, more important, can modify file and folder names to avoid whitespace, slashes, & signs or other characters that might cause problems

    As for structuring the database: usually there may be several albums by the same artist, so I could imagine to have a separate artist table, an album table referencing the artists, and a song table referencing the albums

    Musicman

  3. #3
    Senior Member andrthad's Avatar
    Join Date
    Apr 2002
    Location
    Oklahoma - USA
    Posts
    154
    Hi musicman,

    I was hoping I would get you. You helped me in the past with a PHP that actually read the mp3 file names from within a folder. I was thinking that a music player that played files from a mysql database would be sweet, however, I would want the values in the database to be updated directly from the folder structure on your webserver.

    For instance like you said have an artist table, an album table, and a song name table. Have an admin php script that reads the first layer of folders and understands that these are the artists names that should appear in the artist table name. Then reads the next layer of folders and interprets that to be all the artist's names. Lastly the third level down would be all the mp3s. I actually have the php script for that.

    I'm starting to see the layout. Build the tables in mysql. Upload mp3 files with correct folder structure (artist / album / song.mp3). Build a php admin page to update tables with currect web folder structure. Enable the flash music player to read the mysql database. What do you think?
    PC | 1.7GHz P4 | 256MB RAM | FLASH MX | IE6 | WIN XP | BROADBAND

  4. #4
    Registered User
    Join Date
    Feb 2001
    Posts
    13,039
    Hi,

    sounds reasonable - now it is up to you to decide how the player will interact with the database, e.g.
    - tree structure
    - search by artist / by album / by song
    - advanced search
    - search keyword in all columns

    Musicman

  5. #5
    Senior Member andrthad's Avatar
    Join Date
    Apr 2002
    Location
    Oklahoma - USA
    Posts
    154
    Musicman,

    You taugth me how to get files within a certain directory:

    <?
    $n = 0;
    $dp = opendir("musicPopular") or die("status=fail");
    while($f = readdir($dp))
    {
    if($f != "." && $f != ".."){
    if($n == 0){
    print "im$n=$f";
    }
    else{
    print "&im$n=$f";
    }
    $n++;
    }
    }
    print "&total=$n";
    ?>

    How would you get only folder names within a certain directory?
    PC | 1.7GHz P4 | 256MB RAM | FLASH MX | IE6 | WIN XP | BROADBAND

  6. #6
    Registered User
    Join Date
    Feb 2001
    Posts
    13,039
    Hi,

    useful php functions is_file() and is_dir() ...

    note: the code should be something like
    Code:
    $dp = opendir("somedir");
    while($f = readdir($dp))
    { if(is_dir("somedir/$f")) ...
    Without putting the somedir into the test, the script would test whether a name found in somedir exists as a directory within the current dir

    Musicman

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center