Results 1 to 11 of 11

Thread: PHP readdir() help, sending to Flash

  1. #1

    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:
    Code:
    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:
    PHP Code:
    <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.

    (make sense?)

    I am curretly using a generic variant of the readdir() script. (failed attempts..LOL)
    PHP Code:
    <?
    $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....

    PHP Code:
    <?
    $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

  2. #2
    www.php.net/isdir

    If it returns true, then go through the files of that directory as well.

    Sorry about the lack of detail in this post. I'll see if I can help you more thoroughly tomorrow (today).
    got pwnt?

  3. #3
    ok... Im starting back at square one...

    this is my PHP script I am trying to get working..

    if I just target this script with my browser.. it doesnt work.. so I need help figuring this out...

    it should be recursive to the _root directory.. meaning.. and subs.. ad subs/subs... should list out in a XML type document like posted above...

    PHP Code:
    <?
    function scandir($dir) {
            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 != 'private'//example restriction: dont want 'private folder' included
                                     
    print "<file name='$file'>$file</file>";
                    
                
    closedir($handle);
            }
    }
    scandir('.');
    ?>

  4. #4
    ok...after some 'messin' around with this php script.. I have it actually 'returning' something.. so the syntax must be

    all fixed.. the PHP must be a little 'wrong' though...

    here is the script I amm currently using:

    PHP Code:
    <?
    function scandir($dir) {
            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 != 'private') {
                                     print 
    "<file name=\"$file\" />";
                    }
                }
                }
            
    closedir($handle);
            }
    }
    scandir('.');
    ?>
    When I target this in my 'browser' directly.. I am expecting to get something like this:

    example directory structure:

    in folder (member1) you have:
    Code:
    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
    Using the script above I am expecting to get an output lik this:
    PHP Code:
    <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

    but it is currently displaying like THIS, in my browser:

    Code:
    CD_marketing_1.gifelvis.jpgadobe.pnghip.pngeric.jpgtrace.jpgjim.jpguvid.jpgflashtrain.jpg..etc..etc.
    no breaks...and no print "<file name=\"$file\" />"

    What can I do to correct this?

  5. #5
    230
    posts
    ||| (--(--(--)--)--) |||
    instead of using print.. use echo

  6. #6
    so have you tested it??

    if you change that to echo instead of print..and target that PHP file with your browser..directly.. do you get a list out of whatever directory you wanted to get??

    I just did.. didnt work...gives the SAME out put as I just described above.. did you miss the post??

    anyone else can help with this PHP script? geez.. I dont know ANY php and Ive gotten this far..

  7. #7
    PHP Code:
    <?
    header
    ("Content-type: text/xml");
    function 
    scandir($dir) {
            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 != 'private') {
                                     print 
    "<file name=\"$file\" />";
                    }
                }
                }
            
    closedir($handle);
            }
    }
    scandir('.');
    ?>
    Sniper, there's hardly a difference between print and echo.
    got pwnt?

  8. #8
    230
    posts
    ||| (--(--(--)--)--) |||
    What can i say... i wanted to up my post count

  9. #9
    Post counts are pretty insignificant. They don't really mean anything.
    got pwnt?

  10. #10
    230
    posts
    ||| (--(--(--)--)--) |||
    have you not anyone else to moan at ?? ffs

  11. #11
    Nope
    got pwnt?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012