Aug 8, 2008

Making A Webserver Directory Listing - Helps you organise your webserver

Free Web Hosting, No Ads > CONTRIBUTE > Tutorials

free web hosting

Making A Webserver Directory Listing - Helps you organise your webserver

sachavdk
I recentely installed IIS with PHP and MySQL on my pc (previous I used UniServer, but that doesn't matter here). But I had always to go to http://localhost/websiteiwanted or I had to create a shortcut on my desktop for every site so I decided to create an "overviewpage". It shows all the websites in your wwwroot with a link to them. If you have folders you don't want to be included, you extense the && check (but I'll explain this lateron)

Here's the total code:
CODE
<ul>
<table cellpadding="3" cellspacing="3" border="0" width="95%">
<?
$dir=opendir('.');
$isdirtrue = false;
while ($file = readdir($dir)){
if($file != '..' && $file !='.' && $file !=''){
 if (is_dir($file)){
  if ($file != 'IIS_Services' && $file != 'RECYCLER' && $file != 'Config' && $file != 'System Volume Information')
  {
   $isdirtrue  = true;
   echo '<tr><td>';
   echo '<a href="'.$file.'/" target="_blank">&nbsp;[&nbsp;'.$file.'&nbsp;]</a>&nbsp;&nbsp;';
   echo '</td></tr>';
  }
 }
}
}
if ($isdirtrue == false) {
echo "<div align='center'>-&nbsp;No projects&nbsp;-</div>";
}
closedir($dir);
clearstatcache();
?></table></ul>

Now I'll explain every step

$dir=opendir('.'); opens the current folder. You could use .. to specify the folder one level up or ./folder/folder to open other folders.

$isdirtrue = false; is going to check if the opened file is a directory lateron in the script, this just initializes it

while ($file = readdir($dir)){ is going to read every "file" in the opened directory. Also . .. are files in the opened folder. This can be convenient sometimes but now they don't matter thats why I'm gonna use following code. To see that the opened file not . or .. is:

if($file != '..' && $file !='.' && $file !=''){

if (is_dir($file)){ checks wheter the file is a directory. if it is one, we go to the next step

if ($file != 'IIS_Services' && $file != 'RECYCLER' && $file != 'Config' && $file != 'System Volume Information'){ here you can specify which folders don't participate in your projects list

$isdirtrue = true; this sets the isdir to true because we have at least one project in the list. more explanation withing some lines

echo '<tr><td>';
echo '<a href="'.$file.'/" target="_blank">&nbsp;[&nbsp;'.$file.'&nbsp;]</a>&nbsp;&nbsp;';
echo '</td></tr>';
these are gonna write a link to the projectfolder

if ($isdirtrue == false) {
echo "<div align='center'>-&nbsp;No projects&nbsp;-</div>";
}
now remember that we just set $isdirtrue to true because we had at least one project? at the beginning of the script we initialized it false. if there wouldn't have been a projectdirectory it would still be false and then it would give a message that there are no projects on your server.

now very important are
closedir($dir); and
clearstatcache(); because if you don't use these, your cache memory will be left full of needless information.
closedir() closes de directory you opened in the beginning of the script and clearstatcache() deletes all "temporary files" from the memory.

Now that's it. I hope lots of people will follow my example and be more neater with their local webserver. tongue.gif wink.gif

 

 

 


Reply

Klass
so how does this work?
I copied your code to notepad saved the file as test.html and nothing came up but:
CODE
[ '.$file.' ]  '; echo ''; } } } } if ($isdirtrue == false) { echo "
- No projects -
"; } closedir($dir); clearstatcache(); ?>


what do you do if you defined the inetpub folder to a different location other than C:\inetpub\wwwroot?

Reply

rvalkass
You need to save it as test.php not as a .html file, Klass.
That should fix your problem. Also, I would like to know if it is possible to make something similar for Apache. Not just the normal directory listing, but one with links and some folders not displayed?

Reply

sachavdk
QUOTE(rvalkass @ Jul 17 2005, 10:56 AM)
You need to save it as test.php not as a .html file, Klass.
That should fix your problem. Also, I would like to know if it is possible to make something similar for Apache. Not just the normal directory listing, but one with links and some folders not displayed?
*


Normally it could serve for Apache Servers. Run the script and see which directories are listed you don't want to

if ($file != 'IIS_Services' && $file != 'RECYCLER' && $file != 'Config' && $file != 'System Volume Information')

IIS_Services, Config are directories I created to install PHP and MySQL, RECYCLER and System Volume Information are part of IIS and can be deleted with apache. IE. you have three directories. Two are project and one is some configuration dir.
1. MyConfiguration
2. Project1
3. Project2

Now you don't want dir MyConfiguration listed, then you simply have to replace
if ($file != 'IIS_Services' && $file != 'RECYCLER' && $file != 'Config' && $file != 'System Volume Information')
by
if ($file != 'MyConfiguration')
.

And for the links, normal it should display a link on every project

this code takes care of that:
CODE
echo '<tr><td>';
  echo '<a href="'.$file.'/" target="_blank">&nbsp;[&nbsp;'.$file.'&nbsp;]</a>&nbsp;&nbsp;';
  echo '</td></tr>';

if it shouldn't work, try this:
CODE
echo '<tr><td>';
  echo '<a href="./'.$file.'/" target="_blank">&nbsp;[&nbsp;'.$file.'&nbsp;]</a>&nbsp;&nbsp;';
  echo '</td></tr>';

 

 

 


Reply

Klass
ok i sill don't understand your how to:

1. You do not tell us to save as a PHP file.
2. Where am I supposed to run this from?
3. Do I need to configure this for a directory since I do not use Inetpub defaults?

Reply

sachavdk
QUOTE(Klass @ Jul 17 2005, 06:36 PM)
ok i sill don't understand your how to:

1. You do not tell us to save as a PHP file.
2. Where am I supposed to run this from?
3. Do I need to configure this for a directory since I do not use Inetpub defaults?
*



1. I've forgotten to tell it, sorry.

2. Wherever you want in your webroot.

3. It doesn't matter if you use Inetpub or some other. Imagine your wwwroot is "C:\MyDocuments\WWW\WEBSERVER\" and you have 5 webprojects in your webroot ie pro1, pro2, pro3, pro4 and pro5, each is located in "C:\MyDocuments\WWW\WEBSERVER\" so you have
"C:\MyDocuments\WWW\WEBSERVER\pro1\"
"C:\MyDocuments\WWW\WEBSERVER\pro2\"
"C:\MyDocuments\WWW\WEBSERVER\pro3\"
"C:\MyDocuments\WWW\WEBSERVER\pro4\"
"C:\MyDocuments\WWW\WEBSERVER\pro5\"
and maybe some configdir or a dir you dont want to have listed
"C:\MyDocuments\WWW\WEBSERVER\whatever\"

if you place the script in "C:\MyDocuments\WWW\WEBSERVER\" and you replace line 8 (if ($file != 'IIS_Services' && $file != 'RECYCLER' && $file != 'Config' && $file != 'System Volume Information')) by if ($file != 'whatever') the script will give you a list from all projects (pro1 to pro5). If you click one, the script will open the project (directory) in a new window.

You can set this script whereever you like (ie you named this script list.php and set it in your rootdir) and go to http://pathofyourserver/list.php

TO EVERYONE WHO READS THIS:
CODE
if ($file != 'IIS_Services' && $file != 'RECYCLER' && $file != 'Config' && $file != 'System Volume Information')
is just a line of code so dirs I don't want to be listed, are not listed.
If there are no dirs you don't want to be listed change the line to
CODE
if ($file != '')
this way all dirs are listed.

I hope it's clear now to you.

Reply

Adamrosso
Great tutorial, i may need this in the future

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : making, webserver, directory, listing, helps, organise, webserver

  1. [ask] Making Video When We Use An Application In Our Computer?
    asking the best software to make this.. (5)
  2. Making A Picture Viewer Website
    Html programming or javascript (3)
    this is one thing i've struggled with for ages. I want a webpage where there are little
    thumbnails and in the middle somewhere is the main picture. The littole thumbnails or snipets of
    infor when clicked display the main image corresponding to that clicked thumbnail or link. e.g
    pictures of the country side listed in pairs or 3's or 4's in a column and you click each
    one an the main view on the screen displays that particular picture. How is this achieved. Can any
    one gimme a link to a site with templated for that or javascript for that or html code or past....
  3. Open Program Copyrights For Third World Nations
    By making software free many can become employed (4)
    I propose the idea that giving free premium software to those who could never afford a purchase can
    only help the owners of that software. Some say that if a sale was never going to happen it
    can't be a lost sale. I agree. If people can get started learning to use programs they could
    never buy, they may develop skills and abilities that would enable future revenue and loyalty. At
    the same, time a third world nation can have more development as skilled and trained professionals
    grow. Another important issue would be addressed as well. Piracy. By lifting the copyrig....
  4. Making A Screenshot
    A tutorial on how to make a screenshot with MS (0)
    Specs Hardness: 1 Time: about 2 minutes Needings: -A (small) brain -A keyboard -MS Paint
    Steps: 1. Press the Print Screen button on your keyboard. 2. Open Microsoft Paint. 3. Paste
    (CTRL+V). 4. Save/Edit the image. (I prefer saving as .png or .tif) ét voila, you've just got
    yourself a picture /wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif"
    />....
  5. Making A Simple Signature With Adobe Photoshop
    A tutorial to basic signature designing: By Accure (3)
    Specs Hardness: 4 / 10 Time: about 10 minutes Result: My .PSD File: Download it now!
    Needings: -Basic Photoshop knowlegend. -Adobe Photoshop CS2 (Or CS3/CS4) -Brushes set ( available
    here ) -A render ( available here ) Basic knowlegend: Steps: 01. Open Adobe Photoshop,
    and go File > New. 02. select the sizes Width: 350 pixels . Height: 150 pixels . Press OK .
    03. Press the button to maximize the window of your new project. 04. Fill your background with
    black (by using the "fill" function). 05. Press F5, click on the small arrow a....
  6. Making My Own Browser
    Uhm...need a name (6)
    I am currently developing my own Web Browser and I need a name for it /biggrin.gif"
    style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> So if you got any good
    ideas please do post them /biggrin.gif" style="vertical-align:middle" emoid=":D" border="0"
    alt="biggrin.gif" />....
  7. Recommended List Of Money Making Sites
    A list of 10 sites from which easy money can be made (0)
    I just want to let everyone know I have updated my list of money making websites and in my opinion
    the 10 listed are the most reliable and honest money making sites that are free to join available.
    Please review this blog and let me know what you think http://makeeasymoney247.blogspot.com ....
  8. Please Can You Review My Blog
    List of recommended sites for making money online (3)
    I am currently in the process of constructing a list of the best sites through which to make money
    online and would like people to take a look at the sites I have added so far. I am obviously still a
    long way of completing it but just wondering whether people think it is a good site / idea
    http://makeeasymoney247.blogspot.com Also if you have not yet signed up to ClixSense I would
    highly recommend it. You can join for free but you are better of paying the small $10 yearly
    membership fee as this will bring you a ton more paid adverts - more than any other site I ....
  9. Making Calculators with PHP
    Some basic calculator scripts I made. (4)
    Yes, I made some basic calculators to use for simple math problems, nothing big. I'm a newbie at
    php, so if I made something that could be short, long, I am sorry. lol Here is one for adding two
    numbers. CODE <html> <title>Adding 2 numbers </title> <body>
    <h3 align="center">Type in the two numbers you'd like to add
    together.</h3> <form action="add2.php" method="post"> <input
    type="text" name="number1" /><p>+</p> <input type="tex....
  10. I Think That They Should Start Making Boxers For Girls.
    Yes, mermaid started an underwear topic. (4)
    Okay, I'm just warning you now: This may be, by far, the dumbest topic you will ever read. So
    if you don't like reading the stupid random thoughts of an almost-fourteen-year-old, I suggest
    you navigate away from the page as soon as possible. /tongue.gif" style="vertical-align:middle"
    emoid=":P" border="0" alt="tongue.gif" /> I had a random thought today (supprising right? Lol, I
    know) /tongue.gif" style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" /> Guys
    alway talk about how comfy boxers are. And I'm not a dude, so I wouldn't kno....
  11. How To Make An Ultimate Game List.
    If you're making a site on video games or such. (0)
    Hello. I am BuBBaG. You can call me Bubba for short. I'm going to show you how to make an
    Ultimate Game List. First off, we need to make a database, we are going to call this database
    `my_db`, leave out the `'s. Inside that database we will need to create a table
    called `ugl'(Ultimate Game List, duh). To make the table, simply enter this in the Syntax.
    CODE CREATE TABLE ugl ( System char(50), Game char(50), ) In the
    above code, it is stating we are creating a table called ugl, with two columns, System, and Gam....
  12. Reverse Funnel System Making Money On Auto Pilot.
    (2)
    Hi Guys This site provides a very best business opportunity making money from online and also
    it is a home based business.You can earn money in profit-manner.It also provides Reverse funnel
    system making money on auto pilot. Reverse funnel marketing,perpetual leverage payplan,global
    resorts network,gold crown resorts,reverse funnel system,ultimate home business,fullyautomated,think
    and grow rich,home biz,passive income,no phone calling,ultimate solution to home and so on. Cheer"s
    Reverse funnel system making money on auto pilot ....
  13. Where Am I Making Mistake
    (9)
    hello i have just started to learn java by myself and i am stuck here with this example i want to
    show a file in console please tell me where am i making mistake. i am getting erroe variable fin
    maight not be initialised here is the code CODE /** Display a text file To use this
    program,specify the name of file that you want to see */ import java.io.*; class showfile {
        public static void main(String args[])throws IOException     {         int i;
            FileInputStream fin;         try             {             BufferedReader br=new....
  14. How To Display Images Of A Directory
    (4)
    I am trying to do a simple thing. I want to display all the images of a directory on a single page
    with the checkbox next to each image, so that i can select multi images and i can delete selected
    images. Following few lines of code display the images of a directory.. i need help to put the
    check boxes with each image. and I dont understand how can i select multi images with check box and
    then delete them. I hope someone can help. thanks. CODE <?php $path = "./";
    $dir_handle = @opendir($path) or die("Unable to open folde....
  15. Making A Song In Fruity Loops Part Three
    part three precusion (1)
    ok part three now which covers the precusions setup of the small song i built for this tutorial.
    the nesecery files can be downloaded here the image below is included in the precusions folder as
    it mught not be entierly visable within this post so shold you need it its there also the images
    purpose is to enable you to see what i am refering to within this tutorial lateron. now what i
    have done above is blackd out every pattern that has nothing to do with the precusion. so the
    patterns displayed in light grey are the only patterns i will be refering to. ok lets b....
  16. Making Money From Home
    (13)
    .................................
  17. Religion And Science
    Is Science Making God A Thing Of The Past? (5)
    Although science continues to advance to explain otherwise religiously explained ideas, I believe
    that religion will always exist in our world. What do you think? Here's MY thoughts. I'd
    love to hear yours /happy.gif" style="vertical-align:middle" emoid="^_^" border="0" alt="happy.gif"
    /> Science has given explanations that, before, were only offered up in texts such as the Bible
    were the only explanations. For example, the issue of how life came to be. Before, cultures from
    around the world would attribute this phenomenon of life to some fable or myth rev....
  18. Runescape 2 Private Server Guide: Part 1
    making a private server (16)
    According to RuneScape TOS, as long as your private server does not connect/interfere with the
    actual server this 3rd party software is not breaking the real RuneScape TOS. Please use this
    information accordingly. If any RuneScape representative feels that this post is against your TOS,
    please contact Trap17 admins via PM or email. Thank you. This is part 1, focused on making a
    private server and such, if you would like, i will post more on customization in other parts.
    Overview: This guide will explain the basics for building your very own rs private server&....
  19. What Are The Steps To Making A Website?
    (17)
    what are some steps to making a website? im doing a project and i need like 5-7, but id ont know
    waht to put. ....
  20. Making Mods
    (4)
    Just wanted to see if we have a modders in this place. If you are modder, hwo did you get yourself
    into and what mods of games have you made?....
  21. Making Games
    With Game Maker (18)
    Hi. /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> I just
    wanted everyone to know(if you didn't know already. /smile.gif" style="vertical-align:middle"
    emoid=":)" border="0" alt="smile.gif" />) of a pretty cool program called Game Maker. From my
    experience with it, it's very simple, yet you can still make awesome games with it. Now, when I
    say "awesome" keep in mind, you won't be able to make games like "Halo" or something like that
    with it. But you can make pretty cool games still, it is capable of 2D and 3D games, alth....
  22. Make 100% Free Money Online $4000+
    free money making system (18)
    /cool.gif" style="vertical-align:middle" emoid="B)" border="0" alt="cool.gif" /> Hello I am
    posting this site here as I am making money with it every month..It is a step-by-step money making
    system..Best thing is it is 100% free..First I thought that it might be a scam but now as I am
    making 4000$ per moth so now I have to believe it.. I will advise you that
    please give it a try before making any decision..You will also make money..no experience is needed
    and its free..so you have nothing to lose.. you will surely love it.. ....
  23. How To: Make A Simple Php Site
    Making one file show up on all pages using php (21)
    I have looked all over the site and could not find anything that was like this simple, or just like
    this at all.. For some people i know that you are using a basic HTML site...and having a big menu
    if you want to add somthing you have to go into every one of the pages and add or remove or edit
    what you want to do, but with somthing verry simple all you would have to do is edit one file, and
    all of the pages that have the PHP script on them would suddenly change to what that one file is.
    So to start off if you are planning on using this little tirck, the page that you a....
  24. .::gunz Online Clan::.
    making a gunz clan lvl 10+ (16)
    hey im making a gunz online clan you have to be over lvl 10 to get in fill in this form gunz
    name: country: plays a week: time(in GBA) play: level:....
  25. Making Winrar Archives
    and adding password to winrar archives (12)
    **** This tutorial will show you how to put files into .rar Archive and pass worded (if wanted)
    **** What You Will Need Before continuing you will need a couple of thing, first of all you
    need WINRAR , which is a very powerful archive manager. It can reduce size for you email
    attachments, decompress RAR, ZIP and other types of files downloaded from the internet. You can get
    winrar at http://www.rarlabs.com The other thing is that make sure your using Windows XP because
    this is what I used to make this tutorial. I think it works with any other windows not....
  26. Tutorial: Installing D-shoutbox For Ipb V1.2
    Making your installation even easier (12)
    Over the course of the summer I have tried hard to install a shoutbox into a new forum I was
    developing. I went to the Invisionalize forums and found several mods for shoutboxes, but none of
    them seemed to work. I first tried to install the D-Shoutbox, but upon this first try, I was
    unsuccessful. Eventually, after much frustration, and trying other mods, which didn't seem to
    stack up to Dean's features, I was determined to make it work. For some, editing your files (to
    the newbie that is) can be difficult, with everything looking like a foreign language (basi....
  27. Give Me Website Ideas..
    Website Ideas : Something original. Ideas for making a site (30)
    Website Ideas I'm deciding to take down my site, it's getting kind of old and
    boring, but I don't want to just stop with having a site. I need some ideas for something that
    provides a service of some sort to people. There are millions of blogs, I really don't want to
    post about my life on a daily basis anyway. All ideas will be welcomed, I can't seem to think
    of anything at all, so Im asking you. What could my new website be about?....
  28. Inbox Dollars
    Best Money making Site-I Got Paid (28)
    Inbox Dollars is a great site that i found when i was browsing around the net. This Site Offers you
    3 different reward chioces and they are: - 10000 Banner Imprressions- $10 - Gold Membership
    -$17 - Check- $30 I have already gotten the 10000 banner impressoins from them. The ways
    you can earn money are: -$5 when you join the site... -$0.01-0.10 for every paid email
    -$4 for every survey site you join -Up to $50 for for every offer -Unlimited cash for
    games -Umlimited cash for shoppings The offers are very easy to fill out and you ge....
  29. The Sims 2 Bodyshop
    Making clothes for your sims... (35)
    Hiiiiii Any one playing The Sims 2 must have heard from Bodyshop, or is even very handy with it
    and makes his own clothes to use in the game...!! Well Those people I'd like to ask
    about some tip or tricks, because, I tried making clothes, and were pretty on the good way so far,
    but I just kinda have the feeling I dont know all the tricks yet!! Anybody who is familiar
    with this program can leave some tips/tricks, also for others who want to create great clothes for
    their sims???? Thanksss so very much, I have this outfit in my head, but have no ide....
  30. Im Making A Mmorpg >>
    Have a read... (11)
    can you give your ideas for my new game. if you want to help me even more then send me a private
    message Thanks Tyjotr __________________________________________________ HybridHero - the new 3d
    MMORPG (coming soon)....

    1. Looking for making, webserver, directory, listing, helps, organise, webserver

Searching Video's for making, webserver, directory, listing, helps, organise, webserver
Similar
[ask] Making
Video When
We Use An
Application
In Our
Computer? -
asking the
best
software to
make this..
Making A
Picture
Viewer
Website -
Html
programming
or
javascript
Open Program
Copyrights
For Third
World
Nations - By
making
software
free many
can become
employed
Making A
Screenshot -
A tutorial
on how to
make a
screenshot
with MS
Making A
Simple
Signature
With Adobe
Photoshop -
A tutorial
to basic
signature
designing:
By Accure
Making My
Own Browser
- Uhm...need
a name
Recommended
List Of
Money Making
Sites - A
list of 10
sites from
which easy
money can be
made
Please Can
You Review
My Blog -
List of
recommended
sites for
making money
online
Making
Calculators
with PHP -
Some basic
calculator
scripts I
made.
I Think That
They Should
Start Making
Boxers For
Girls. -
Yes, mermaid
started an
underwear
topic.
How To Make
An Ultimate
Game List. -
If
you're
making a
site on
video games
or such.
Reverse
Funnel
System
Making Money
On Auto
Pilot.
Where Am I
Making
Mistake
How To
Display
Images Of A
Directory
Making A
Song In
Fruity Loops
Part Three -
part three
precusion
Making Money
From Home
Religion And
Science - Is
Science
Making God A
Thing Of The
Past?
Runescape 2
Private
Server
Guide: Part
1 - making a
private
server
What Are The
Steps To
Making A
Website?
Making Mods
Making Games
- With Game
Maker
Make 100%
Free Money
Online
$4000+
- free money
making
system
How To: Make
A Simple Php
Site -
Making one
file show up
on all pages
using php
.::gunz
Online
Clan::. -
making a
gunz clan
lvl 10+
Making
Winrar
Archives -
and adding
password to
winrar
archives
Tutorial:
Installing
D-shoutbox
For Ipb V1.2
- Making
your
installation
even easier
Give Me
Website
Ideas.. -
Website
Ideas :
Something
original.
Ideas for
making a
site
Inbox
Dollars -
Best Money
making
Site-I Got
Paid
The Sims 2
Bodyshop -
Making
clothes for
your sims...
Im Making A
Mmorpg
>> -
Have a
read...
advertisement



Making A Webserver Directory Listing - Helps you organise your webserver



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE