|
|
|
|
![]() ![]() |
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"> [ '.$file.' ]</a> '; echo '</td></tr>'; } } } } if ($isdirtrue == false) { echo "<div align='center'>- No projects -</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"> [ '.$file.' ]</a> '; echo '</td></tr>'; these are gonna write a link to the projectfolder if ($isdirtrue == false) { echo "<div align='center'>- No projects -</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. |
|
|
|
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? |
|
|
|
Jul 17 2005, 08:56 AM
Post
#3
|
|
|
apt-get moo ![]() Group: [MODERATOR] Posts: 2,054 Joined: 28-May 05 From: Hertfordshire, England Member No.: 7,593 ![]() |
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? |
|
|
|
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"> [ '.$file.' ]</a> '; echo '</td></tr>'; if it shouldn't work, try this: CODE echo '<tr><td>';
echo '<a href="./'.$file.'/" target="_blank"> [ '.$file.' ]</a> '; echo '</td></tr>'; |
|
|
|
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? |
|
|
|
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. |
|
|
|
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
|
|
|
|
![]() ![]() |
Similar Topics