PHP readdir() help, sending to Flash

Hi- I original had a question… and I dont think Im really getting anywhere. (just dont know enough about PHP to figure it out I guess)

so I am starting over and re-thinking my approach…

my first step is to:

1.) write a php script using readdir() that can OUTPUT an XML string/object that represents the directory structure. including sub-directories and their contents, back to Flash

I have only been partially sucessful

example:

in folder (member1) you have:


example1.doc
file.txt
sound.mp3
sub-directory1 (folder)
    -file.txt
    -something.jpg
    -whatever.swf
sub-directory2 (folder)
    -file2.txt
    -something2.jpg
    -whatever2.swf
sub-directory3 (folder)
    -file3.txt
    -something3.jpg
    -whatever3.swf
demo.fla
something.wav

I need to configure my readdir() script to output output an XML file like:

or something similar:


<member>
    <file label=test.txt>test.txt</file>
    <file label=music.mp3>music.mp3</file>
    <directory name=folder1>
        <file label=whatever.doc>whatever.doc</file>
        <file label=sound.mp3>sound.mp3</file>
        <file label=image1.jpg>image1.jpg</file>
    </directory>
    <file label=songs.mp3>songs.mp3</file>
    <file label=demo.swf>demo.swf</file>
    <directory name=folder2>
        <file label=whatever2.doc>whatever2.doc</file>
        <file label=sound2.mp3>sound2.mp3</file>
        <file label=image2.jpg>image2.jpg</file>
    </directory>
</member>


or


<member>
    <file label=test.txt data=test.txt />
    <file label=music.mp3 data=music.mp3 />
    <directory label=folder1>
        <file label=whatever.doc data=whatever.doc />
        <file label=sound.mp3 data=sound.mp3 />
        <file label=image1.jpg data=image1.jpg />
    </directory>
    <file label=songs.mp3 data=songs.mp3 />
    <file label=demo.swf data=demo.swf />
    <directory label=folder2>
        <file label=whatever2.doc data=whatever2.doc />
        <file label=sound2.mp3 data=sound2.mp3 />
        <file label=image2.jpg data=image2.jpg />
    </directory>
</member>

something workable with the tree component…where I am able to:

grab the USER NAME/DIRECTORY (should be sent to PHP when the script is called)

and either grab the file name “AND/OR” grab the sub directories and the file name…

so when I click on any of the entries in the FOLDER/NODE in the tree component (once populated)… I can build a STRING to the path of that file.

I would prefer to NOT use the PHP way of building an XML document…as my PHP knowledge is 0%…and that would be a bit much to undertake for this purpose I think… I’d liek to stay with using the string+var+streing builing method I am working with below. :slight_smile:

(make sense?)

I am curretly using a generic variant of the readdir() script. (failed attempts…LOL)


<?
$found = array();
function scandir($dir) {
    global $found;
        if($handle = opendir($dir)) {      
        while(($file = readdir($handle)) !== false){
                        if($file != '.' && $file != '..'){
                                if(is_dir("$dir/$file")){  
                    print "<directory name=\"$file\">";
                          scandir("$dir/$file");
                          print "</directory>";
                }else if($file != 'big') // just an example restriction: dont want 'big'{
                         print "<file name=\"$file\">\"$file\"</file>";
                                        $found[] = "$dir/$file";
                }
            }
                }
        closedir($handle);
        }
}
scandir('.');
print "&nameReturn=" . join($found, "|");
?>


and…


<?
$found = array();
function scandir($dir) {
    global $found;
        if($handle = opendir($dir)) {      
        while(($file = readdir($handle)) !== false){
                        if($file != '.' && $file != '..'){
                                if(is_dir("$dir/$file")){  
                    print "<directory name=\"$file\">";
                                        //print "&nameReturn=" . join("<directory name=\"$file\">";
                          scandir("$dir/$file");
                          print "</directory>";
                                        //print "&nameReturn=" . join("</directory>")"
                }else if($file != 'big') // just an example restriction: dont want 'big'{
                         print "<file name=\"$file\">\"$file\"</file>";
                                        //print "&nameReturn=" . join("<file name=\"$file\">\"$file\"</file>")
                }
            }
                }
        closedir($handle);
        }
}
scandir('.');
?>

any help on getting the readdir() and output string (XML) back to Flash will be appreciated.

Thanks :slight_smile: