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 2 of 2

Thread: DIR list Help

  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation DIR list Help

    i need to add filesize and hide extension filter to this code.
    thanks in advance.

    <?php
    $str = "<root>";

    function readfromhere($path=".")
    {
    global $str;
    $currentPath=($path == '.' ? './Shared/' : $path.'/');
    //echo "";
    //var_dump($currentPath);
    //echo "";
    if ($handle = opendir($currentPath)) {
    while (false !== ($file = readdir($handle))) {
    //echo "";
    //var_dump($file);
    //echo "\n";
    //var_dump(is_dir($currentPath.$file));
    //echo "";

    if (is_dir($currentPath.$file) && $file != "." && $file != "..") {
    $str.='<node type="folder" name="'.$file.'">';
    readfromhere($currentPath.$file);
    $str.='</node>';
    } else if ($file != "." && $file != "..") {
    $str.='<node type="file" name="'.$file.'" path="'.preg_replace('/\.\/+/i','',$currentPath).$file.'">
    </node>';
    }
    }
    closedir($handle);
    }
    return $str;
    }

    readfromhere();
    $str.="</root>";

    header('Content-Type: text/xml');
    echo $str;
    ?>

  • #2
    New Coder
    Join Date
    Aug 2008
    Posts
    17
    Thanks
    4
    Thanked 1 Time in 1 Post
    Quote Originally Posted by mnieves View Post
    i need to add filesize and hide extension filter to this code.
    thanks in advance.

    Code:
    <?php
    $str = "<root>";
    
    function readfromhere($path=".")
    {
    global $str;
    $currentPath=($path == '.' ? './Shared/' : $path.'/');
    //echo "";
    //var_dump($currentPath);
    //echo "";
    if ($handle = opendir($currentPath)) {
    while (false !== ($file = readdir($handle))) {
    //echo "";
    //var_dump($file);
    //echo "\n";
    //var_dump(is_dir($currentPath.$file));
    //echo "";
    
    if (is_dir($currentPath.$file) && $file != "." && $file != "..") {
    $str.='<node type="folder" name="'.$file.'">';
    readfromhere($currentPath.$file);
    $str.='</node>';
    } else if ($file != "." && $file != "..") {
    $str.='<node type="file" name="'.$file.'" path="'.preg_replace('/\.\/+/i','',$currentPath).$file.'">
    </node>';
    }
    }
    closedir($handle);
    }
    return $str;
    }
    
    readfromhere();
    $str.="</root>";
    
    header('Content-Type: text/xml');
    echo $str;
    ?>
    File Size:
    $filesize = filesize($file);

    Extension filter:
    $path_info = pathinfo($file);
    $filtered = $path_info['filename'];


    There you go
    (This is assuming $file is ur file handle)


  •  

    Posting Permissions

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