The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 6 of 6

Thread: PHP File List

  1. #1

    PHP File List

    I'm a newbie when it comes to php, so I decided to create a little project for myself to kind of start to learn the language, a script that creates a file list of the contents of a folder, displays them as links with icons according to what file type they are. I have done that and it works great except it doesn't recognize what is a folder sometimes in subdirectories.

    The Code:
    PHP Code:
    <title>Seth's Server</title>
    <style type="text/css">
    <!--
    .title {
        font-family: Arial, Helvetica, sans-serif;
        font-size: large;
        font-weight: bold;
    }
    a:link {
        color: #666666;
        text-decoration: none;
        border: none;
        outline: none;
    }
    a:visited {
        text-decoration: none;
        color: #666666;
        border: none;
    }
    a:hover {
        text-decoration: none;
        color: #999999;
        border: none;
    }
    a:active {
        text-decoration: none;
        border: none;
    }
    .normal {
        font-family: Arial, Helvetica, sans-serif;
        font-size: small;
        font-style: normal;
        color: #000000;
        text-decoration: none;
        border: none #000000;
    }

    -->
    </style>
    <?php
    $folder 
    $_GET['folder'];
    echo 
    "<div class='title'>My Server:</div>";
    function 
    ls ($curpath) {
        if(
    $curpath == ""){
            
    $curpath ".";
        }
        
    $handle opendir($curpath);
        echo(
    "<b>$folder</b>");
        echo 
    "<blockquote>";
        while (
    $file readdir($handle)) {
            if(
    $curpath != "." && $file == ".."){
                
    $icon "left-orange.gif";
                
    $iconPath "/images/icons/".$icon;
                echo(
    "<a class='normal' href='".$PHP_SELF."?folder='..'><img src='".$iconPath."' border='0'>&nbsp;ROOT</a><br>");
            }
            if(
    $file != "." && $file != "..") {
                 if (
    is_dir($file)) {
                     
    $icon "folder-orange.gif";
                    
    $iconPath "/images/icons/".$icon;
                    
    //$curpath = $curpath."/".$file;
                     
    echo("<a class='normal' href='".$PHP_SELF."?folder=".$curpath."/".$file."'><img src='".$iconPath."' border='0'>&nbsp;".$file."</a><br>");
                    
    //ls($curpath);
                 
    }
            }
        }
        
    closedir($handle);
        
    $handle opendir($curpath);
        while (
    $file readdir($handle)) {
            if(
    $file != "." && $file != ".." && $file != ".htaccess") {
                if (
    is_dir($file)) {
                }else{
                     
    $fileInfo pathinfo($file);
                    
    $extension $fileInfo['extension'];
                    
    $icon getIcon($extension);
                    
    $iconPath "/images/icons/".$icon;
                    echo(
    "<a style='normal' href='".$curpath."/".$file."'><img src='".$iconPath."' border='0'>&nbsp;".$file."<br>");
                }
            }
        }
        
    closedir($handle);
        echo 
    "</blockquote>";
        return;
    }    
    function 
    getIcon($extension){
        
    $extension strtolower($extension);
        switch (
    $extension){
        case 
    "php":
            return 
    "web-page-green.gif";
            break;
        case 
    "jpg":
            return 
    "jpg.gif";
            break;
        case 
    "bmp":
            return 
    "bmp.gif";
            break;
        case 
    "png":
            return 
    "png.gif";
            break;
        case 
    "gif":
            return 
    "gif.gif";
            break;
        case 
    "mp3":
            return 
    "mp3-music-file.gif";
            break;
        }
        return 
    "file.gif";
    }
    $startpath $folder;
    ls($startpath);
    ?>
    Thank you for any help or insight you could provide.

    XBOX LIVE GAMERTAG: Icr125riderI


  2. #2
    Do you guys need more info? Please feel free to ask for more information, I tried to provide as much as I could. Thanks again.

    XBOX LIVE GAMERTAG: Icr125riderI


  3. #3
    you have to be careful with a setup like this because someone could use the $_GET variable to drill down into your included files, including your passwords.

  4. #4
    I see, I have .htaccess files set up though so I think I should be ok right?

    XBOX LIVE GAMERTAG: Icr125riderI


  5. #5

  6. #6
    lol, ok

    XBOX LIVE GAMERTAG: Icr125riderI


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