SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Own server page

  1. #1
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,898
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Own server page

    I have my own web server installed on my pc via WAMP 5. This server is accessible to anyone over the network. The main page that appears when someone accesses the main folder of the server is dull and boring with Index of / at the top and a list of files and folders below.

    I would like to create my own page to put in there ie: index.php so that anyone who accesses the server would get this new page. My question is how do i get a list of all the files and folders being shown on this new page whivh is browsable and an icon is shown next to them to show what type of file it is or whether it is a folder. I also need to know how to show the file size of the file or folder?

    Thankyou

    Neil

  2. #2
    SitePoint Addict buildakicker's Avatar
    Join Date
    Jun 2005
    Location
    NorCal
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi you need to use @opendir() and loop through all the files. In order to add an icon in front of the file, you need to ECHO an image in front of each file that gets output. If you want a different image in front of each type of file, this will take an if or for statement...

    check out this code:

    Code:
    <? 
    
    /** 
    *  Change  the  path  to  your  folder. 
    * 
    *  This  must  be  the  full  path  from  the  root  of  your 
    *  web  space.  If  you're  not  sure  what  it  is,  ask  your  host. 
    * 
    *  Name  this  file  index.php  and  place  in  the  directory. 
    */ 
    
    //  Define  the  full  path  to  your  folder  from  root 
    $path  =  "/"; 
    
    //  Open  the  folder 
    $dir_handle  =  @opendir($path)  or  die("Unable  to  open  $path"); 
    
    //  Loop  through  the  files 
    while  ($file  =  readdir($dir_handle))  { 
    
    if($file  ==  "."  ||  $file  ==  ".."  ||  $file  ==  "index.php"  ) 
    
    continue; 
    echo  "<a  href=\"$file\">$file</a><br>&gt;"; 
    
    } 
    
    //  Close 
    closedir($dir_handle); 
    
    ?>
    Hope that helps!
    Last edited by buildakicker; Dec 19, 2006 at 14:39.
    SKILEASES.COM - FREE rental listings!
    WILDFIREBLOG.COM - Wildland Fire microblog!

  3. #3
    SitePoint Addict buildakicker's Avatar
    Join Date
    Jun 2005
    Location
    NorCal
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, to show the size of the file, you need to use this:

    Code:
    <?php
    
    // outputs e.g.  somefile.txt: 1024 bytes
    
    $filename = 'somefile.txt';
    echo $filename . ': ' . filesize($filename) . ' bytes';
    
    ?>
    SKILEASES.COM - FREE rental listings!
    WILDFIREBLOG.COM - Wildland Fire microblog!


Bookmarks

Posting Permissions

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