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 14 of 14
  1. #1
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Mapping a folder?

    I have a folder /filesys

    I want to make a map (directory) of all the files in the folder filesys.

    I want the map to show each file and link to each file so that you can view them. How might I do this?

    Thanks
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #2
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anyone?
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You just confuse me lol

    Are you wanting mapping or a script to show all files in a directory?

  • #4
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry, I want to show all files in a directory and the files linked to their respective files. So if it shows up info.php i want it linked to info.php

    Thanks,

    Stevie
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #5

  • #6
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a lot for your help, but I kinda wanted to learn how to make one by myself? Would someone mind giving me a lesson on how to do it? It would be really appreciated.

    Thanks for the continued help.
    Last edited by SDP2006; 11-28-2003 at 03:33 PM.
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #7
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts

  • #8
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, I'll have to try it this evening.
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #9
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just in case that didn't satify your hunger

    http://www.phpclasses.org/browse.html/package/1376.html

  • #10
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay, here is what I have
    PHP Code:
    <?php
    $dir 
    "/usr/local/psa/home/vhosts/net-riches.com/httpdocs/filesys/";

    if (
    is_dir($dir)) {
    if (
    $dh opendir($dir)) {
    while ((
    $file readdir($dh)) !== false){
    if(
    preg_match("/php/"$file)){
    print 
    "<img src=\"webscript.gif\">";
    print 
    " <a href='http://www.net-riches.com/filesys/$file'>$file</a>";
    print 
    "<br>";
    }
    if(
    preg_match("/html/"$file)){
    print 
    "<img src=\"webpage.gif\">";
    print 
    " <a href='http://www.net-riches.com/filesys/$file'>$file</a>";
    print 
    "<br>";
    }
    if(
    preg_match("/gif/"$file)){
    print 
    "<img src=\"image.gif\">";
    print 
    " <a href='http://www.net-riches.com/filesys/$file'>$file</a>";
    print 
    "<br>";
    }
    }
    closedir($dh);
    }
    }
    ?>
    It works, and satisfies my needs, but I want the files to be in alphabetical order. Anyone know How I might do that?

    Thanks
    Last edited by SDP2006; 12-14-2003 at 09:14 PM.
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #11
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anyone?
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #12
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    if you have php>=4.3.0 , use glob();


    PHP Code:
    <?
    $directory 
    'e:\phpdev\www' ;
    chdir$directory ) ;
    $yaks glob'*' ) ;
    natcasesort$yaks ) ;

    foreach( 
    $yaks as $y ){
        
    $str .= '<a href="' $y '">' $y '</a><br />' ;
    }

    echo 
    $str ;
    ?>

    you can simulate glob() on *NIX if you have an older version ...

    PHP Code:
    <?
    if( phpversion() < '4.3.0' ) {
        function 
    glob($pattern){
            
    exec'ls | grep '.$pattern $yaks );
            foreach(
    $yaks as $v){
                
    $rets[] = $v ;
            }
            return 
    $v;
        }
    }
    ?>
    you may be able to do something similar on windows with 'find' but I never tried.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #13
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the reply. I'm a little confused. Can you show me using the code in my previous post?

    Appreciate It!

    Stevie
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #14
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    ...not really as your posted code just prints stuff as it finds it.
    to be able to sort the data in anyway you need to be loading the results of your search into arrays which can then be sorted using PHP's built in functions

    ..one way..
    PHP Code:
    <?php
    $dir 
    "/usr/local/psa/home/vhosts/net-riches.com/httpdocs/filesys/";
    if (
    is_dir($dir)) {
        if ( 
    $dh opendir$dir ) ) {
            while ( (
    $file readdir$dh )) !== false){
    /*
        one of a myriad of ways of loading into an array .. NOT the best but hopefully obvious
        this is simplistic so find a better way
    */
                
    switch( substr$file ,-4) ){
                    case(
    '.php'): $php[] = $file ;break;
                    case(
    'html'): $html[] = $file ;break;
                    case(
    '.gif'): $gif[] = $file ;break;
                    default:
    $other[] = $file ;
                }

            }
        
    closedir($dh);
        }
    }
    /* this sorts the php array in the way a human might want to read it */
    /* but also see sort() asort() etc */
    natcasesort$php ) ;

    /*test it*/
    print_r$php ); print_r$other ) ;//etc

    ok now all that did was load data into arrays , you still have to display but a simple ..

    PHP Code:
    <?
    foreach( $php as $y ){
        
    $str .= '<a href="' $y '">' $y '</a><br />' ;
    }
    echo 
    $str;
    ?>
    would suffice;

    still check if your system has glob() available as it is so much cleaner than opendir and friends.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

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