Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Making A Webserver Directory Listing, Helps you organise your webserver
sachavdk
post Jul 16 2005, 11:10 PM
Post #1


Member [Level 1]
****

Group: Members
Posts: 62
Joined: 11-July 05
Member No.: 9,266



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
Go to the top of the page
 
+Quote Post
Klass
post Jul 17 2005, 01:38 AM
Post #2


Advanced Member
*******

Group: Members
Posts: 147
Joined: 2-June 05
From: Klass-World
Member No.: 7,802



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?
Go to the top of the page
 
+Quote Post
rvalkass
post Jul 17 2005, 08:56 AM
Post #3


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 2,054
Joined: 28-May 05
From: Hertfordshire, England
Member No.: 7,593
Spam Patrol



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?
Go to the top of the page
 
+Quote Post
sachavdk
post Jul 17 2005, 02:53 PM
Post #4


Member [Level 1]
****

Group: Members
Posts: 62
Joined: 11-July 05
Member No.: 9,266



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>';
Go to the top of the page
 
+Quote Post
Klass
post Jul 17 2005, 04:36 PM
Post #5


Advanced Member
*******

Group: Members
Posts: 147
Joined: 2-June 05
From: Klass-World
Member No.: 7,802



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?
Go to the top of the page
 
+Quote Post
sachavdk
post Jul 17 2005, 05:29 PM
Post #6


Member [Level 1]
****

Group: Members
Posts: 62
Joined: 11-July 05
Member No.: 9,266



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.
Go to the top of the page
 
+Quote Post
Adamrosso
post Aug 8 2005, 10:10 AM
Post #7


Advanced Member
*******

Group: Members
Posts: 128
Joined: 6-August 05
Member No.: 10,402



Great tutorial, i may need this in the future
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Making Shadows Without Images(4)
  2. Tutorial: Installing D-shoutbox For Ipb V1.2(12)
  3. Making Winrar Archives(12)
  4. Making And Editing A New Ipb V1.2 Skin(0)
  5. How To Stop Image Hot Linking(17)
  6. How To: Make A Simple Php Site(21)
  7. Making Interactive Cds With Flash(2)
  8. Php Script To Make A Link List(6)
  9. How To Protect A Directory From Being Viewed(4)
  10. Making A Dynamic Page On Blogspot(5)
  11. Making The Popular Id Browsing For Your Site.(17)
  12. Making a java based program(3)
  13. Making A One Page Does All Website In Phph(2)
  14. Creating A Resume(1)
  15. Making A Song In Fruity Loops Part 2(0)
  1. Making A Song In Fruity Loops Part Three(1)
  2. Ftp In Visual Basic 6.0(0)
  3. How To Make An Ultimate Game List.(0)
  4. Making Calculators with PHP(4)


 

Display Mode: Standard ·