Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts

    (scandir) Folder Directory (Array) into formated dropbox

    Iv come across the following PHP script that scans the directory all the way through.

    It prints out an Array, well formated and layed out. Im wanting to make it into a formated Drop box, that displays how deep into the Folder structure it is.

    Heres the Source

    PHP Code:
    <?php
    function rec_scandir($dir)
    {
        
    $files = array();
        if ( 
    $handle opendir($dir) ) {
            while ( (
    $file readdir($handle)) !== false ) {
                if ( 
    $file != ".." && $file != "." ) {
                    if ( 
    is_dir($dir "/" $file) ) {
                        
    $files[$file] = rec_scandir($dir "/" $file);
                    }else {
                        
    $files[] = $file;
                    }
                }
            }
            
    closedir($handle);
            return 
    $files;
        }
    }
    function 
    cmp($a$b)
    {
        if ( 
    is_string($a) && is_string($b) ) {
            return 
    strcmp($a$b) > : -1
        }elseif ( 
    is_int($a) && is_int($b) ) {
            return 
    $a $b : -1;
        }elseif ( 
    is_int($a) && is_string($b) ) {
            return 
    1;
        }elseif ( 
    is_string($a) && is_int($b) ) {
            return -
    1;
        }else {
            return 
    0;
        }
    }
    function 
    array_ukmultisort(&$arr$func) {
        
    uksort($arr$func);
        while ( list(
    $key$val) = each($arr) ) {
            if ( 
    is_array($val) ) {
                
    array_ukmultisort($arr[$key], $func);
            }
        }
    }
    $dir rec_scandir(".");
    array_ukmultisort($dir"cmp");
    echo 
    "<pre>";
    print_r($dir);
    echo 
    "</pre>";
    ?>
    Prints this Array

    Code:
    Array
    (
        [flashmyadmin] => Array
            (
                [LEEME] => Array
                    (
                        [0] => leeme.linux.txt
                        [1] => leeme.linux.utf8.txt
                        [2] => leeme.txt
                        [3] => leeme.utf8.txt
                    )
                [LEGGIMI] => Array
                    (
                        [0] => leggimi.linux.txt
                        [1] => leggimi.linux.utf8.txt
                        [2] => leggimi.txt
                        [3] => leggimi.utf8.txt
                    )
                [LISEZMOI] => Array
                    (
                        [0] => lisezmoi.linux.txt
                        [1] => lisezmoi.linux.utf8.txt
                        [2] => lisezmoi.txt
                        [3] => lisezmoi.utf8.txt
                    )
                [README] => Array
                    (
                        [0] => readme.linux.txt
                        [1] => readme.txt
                    )
                [copyleft] => Array
                    (
                        [0] => copyleft.fla
                        [1] => copyleft.htm
                        [2] => copyleft.swf
                        [3] => sample.xml
                        [4] => UserDefinedMethods.as
                    )
                [gauge] => Array
                    (
                        [0] => gaugeClip.swf
                    )
                [help] => Array
                    (
                        [swf] => Array
                            (
                                [en] => Array
                                    (
                                        [0] => basecreate.swf
                                        [1] => basedrop.swf
                                        [2] => basewin.swf
                                        [3] => fieldcreate.swf
                                        [4] => fieldupdwin.swf
                                        [5] => fieldwin.swf
                                        [6] => gotoupd.swf
                                        [7] => helpy.swf
                                        [8] => host.swf
                                        [9] => idpass.swf
                                        [10] => indexcreate.swf
                                        [11] => indxlistwin.swf
                                        [12] => indxupdwin.swf
                                        [13] => listwin.swf
                                        [14] => noutf8.swf
                                        [15] => savepass.swf
                                        [16] => savewin.swf
                                        [17] => sortwin.swf
                                        [18] => sqlwin.swf
                                        [19] => statuswin.swf
                                        [20] => tablecreate.swf
                                        [21] => tabledrop.swf
                                        [22] => tablewin.swf
                                        [23] => unique.swf
                                        [24] => updwin.swf
                                        [25] => xmedia.swf
                                    )
                                [fr] => Array
                                    (
                                        [0] => basecreate.swf
                                        [1] => basedrop.swf
                                        [2] => basewin.swf
                                        [3] => fieldcreate.swf
                                        [4] => fieldupdwin.swf
                                        [5] => fieldwin.swf
                                        [6] => gotoupd.swf
                                        [7] => helpy.swf
                                        [8] => host.swf
                                        [9] => idpass.swf
                                        [10] => indexcreate.swf
                                        [11] => indxlistwin.swf
                                        [12] => indxupdwin.swf
                                        [13] => listwin.swf
                                        [14] => noutf8.swf
                                        [15] => savepass.swf
                                        [16] => savewin.swf
                                        [17] => sortwin.swf
                                        [18] => sqlwin.swf
                                        [19] => statuswin.swf
                                        [20] => tablecreate.swf
                                        [21] => tabledrop.swf
                                        [22] => tablewin.swf
                                        [23] => unique.swf
                                        [24] => updwin.swf
                                        [25] => xmedia.swf
                                    )
                                [it] => Array
                                    (
                                        [0] => basecreate.swf
                                        [1] => basedrop.swf
                                        [2] => basewin.swf
                                        [3] => fieldcreate.swf
                                        [4] => fieldupdwin.swf
                                        [5] => fieldwin.swf
                                        [6] => gotoupd.swf
                                        [7] => helpy.swf
                                        [8] => host.swf
                                        [9] => idpass.swf
                                        [10] => indexcreate.swf
                                        [11] => indxlistwin.swf
                                        [12] => indxupdwin.swf
                                        [13] => noutf8.swf
                                        [14] => savepass.swf
                                        [15] => savewin.swf
                                        [16] => sortwin.swf
                                        [17] => sqlwin.swf
                                        [18] => statuswin.swf
                                        [19] => tablecreate.swf
                                        [20] => tabledrop.swf
                                        [21] => tablewin.swf
                                        [22] => unique.swf
                                        [23] => updwin.swf
                                        [24] => xmedia.swf
                                    )
                                [pt] => Array
                                    (
                                    )
                                [sp] => Array
                                    (
                                    )
                            )
                        [voice] => Array
                            (
                                [en] => Array
                                    (
                                    )
                                [fr] => Array
                                    (
                                        [0] => helpy.mp3
                                    )
                                [it] => Array
                                    (
                                    )
                                [pt] => Array
                                    (
                                    )
                                [sp] => Array
                                    (
                                    )
                            )
                        [0] => en_help_labels.xml
                        [1] => en_help_labels_title.xml
                        [2] => fr_help_labels.xml
                        [3] => it_help_labels.xml
                        [4] => pt_help_labels.xml
                        [5] => sp_help_labels.xml
                    )
                [php] => Array
                    (
                        [0] => class.inc.php
                        [1] => default.lang.flash.txt
                        [2] => en.flash.inc.php
                        [3] => en.php.inc.php
                        [4] => flashmyadmin.php
                        [5] => flashmyadmin_test.php
                        [6] => fmatest.xml
                        [7] => footxml.inc.php
                        [8] => fr.flash.inc.php
                        [9] => fr.php.inc.php
                        [10] => headxml.inc.php
                        [11] => it.flash.inc.php
                        [12] => it.php.inc.php
                        [13] => params.xml
                        [14] => pt.flash.inc.php
                        [15] => pt.php.inc.php
                        [16] => sp.flash.inc.php
                        [17] => sp.php.inc.php
                    )
                [sounds] => Array
                    (
                        [0] => helpvoiceon.mp3
                        [1] => rthelpoff.mp3
                        [2] => rthelpvoiceon.mp3
                    )
                [xmedia] => Array
                    (
                        [flash] => Array
                            (
                                [0] => null
                            )
                        [html] => Array
                            (
                                [0] => null
                            )
                        [images] => Array
                            (
                                [gif] => Array
                                    (
                                        [0] => null
                                    )
                                [jpg] => Array
                                    (
                                        [0] => null
                                    )
                            )
                        [sounds] => Array
                            (
                                [0] => null
                            )
                        [txt] => Array
                            (
                                [0] => null
                            )
                        [videos] => Array
                            (
                                [0] => null
                            )
                    )
                [0] => clo.swf
                [1] => copyleft.swf
                [2] => flash.js
                [3] => flashmyadmin.htm
                [4] => flashmyadmin.swf
                [5] => flashmyadmin_980x580.htm
                [6] => index.htm
                [7] => licence.txt
                [8] => logo2.ico
            )
        [0] => dossier.gif
        [1] => email.php
        [2] => index.php
        [3] => index1.php
        [4] => index2.php
        [5] => none.php
        [6] => report.php
        [7] => temp.html
        [8] => Thumbs.db
    )
    This is how I would like to format the Drop Box

    Code:
    <select>
    <option>Directory Folder Structure</option>
    <option>&nbsp;&nbsp;data</option>
    <option>&nbsp;&nbsp;flashmyadmin</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;copyleft</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gauge</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;help</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;swf</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;en</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fr</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;it</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pt</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sp</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;voice</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;en</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fr</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;it</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pt</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sp</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LEEME</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LEGGIMI</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LISEZMOI</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;php</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;README</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sounds</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xmedia</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flash</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;html</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;images</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gif</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jpg</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sounds</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;txt</option>
    <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;videos</option>
    <option>&nbsp;&nbsp; Glossary</option>
    </select>

    I would also want the VALUE be the URL to that folder. And I dont want (files.*) to show up
    Last edited by glish_dreams; 01-18-2008 at 04:14 AM. Reason: Array Formatting


 

Posting Permissions

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