GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 10-Mar-2006, 02:47
iota iota is offline
New Member
 
Join Date: Feb 2006
Posts: 9
iota is on a distinguished road

Hiding the display of index.php from dir file listing


Hi Php Masters,

How do I hide the display of index.php from Dir Files Listing ?

The php code in index.php is

PHP Code:

<?php

if ($handle = opendir('.')) {
   echo "<ol>" ;
   while (false !== ($file = readdir($handle))) {

       if ($file != "." && $file != "..") {
     
           echo "<b><li><a href='$file'>$file</a>   </li></b>\n";                          


            }         
             
   }
   echo "</ol>";
   $handle = fopen($file, "rb");
   $contents = fread($handle, filesize($file));
   fclose($handle);   
   closedir($handle);
}
?>


Thank you extremely much.
  #2  
Old 10-Mar-2006, 11:34
TreyAU21's Avatar
TreyAU21 TreyAU21 is offline
Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 116
TreyAU21 has a spectacular aura aboutTreyAU21 has a spectacular aura about

Re: Hiding the display of index.php from dir file listing


Quote:
Originally Posted by iota
PHP Code:

while (false !== ($file = readdir($handle))) {

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



First of all... and this might be a typo, but I'm not sure of the !== operator in the while loop? I assume that you meant !=.

With regards to filtering out displaying the index.php file, you can simply add another && to your conditional if statement to exclude viewing the index.php files:

PHP Code:

if ($file != "." && $file != ".." && $file != "index.php") { 



That should do it.
__________________
If practice makes perfect and nobody's perfect... why practice?

Homepage: http://www.treywhite.com
Blog: http://www.treywhite.com/blog.php
Web Design Company: http://www.ewebproductions.com
  #3  
Old 11-Mar-2006, 08:03
iota iota is offline
New Member
 
Join Date: Feb 2006
Posts: 9
iota is on a distinguished road

Re: Hiding the display of index.php from dir file listing


so how do I know the number of files in the same dir ?

for example, if there are five files , then the code returns value of 5 .

thanks again.
  #4  
Old 11-Mar-2006, 11:20
TreyAU21's Avatar
TreyAU21 TreyAU21 is offline
Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 116
TreyAU21 has a spectacular aura aboutTreyAU21 has a spectacular aura about

Re: Hiding the display of index.php from dir file listing


Well... you can simply put a counter inside inside the if statement (that's in the while loop). If you want to count the index.php file (but not display it), you'll need to put that inside an embedded if statement within the other if statement... there you can count it as a file by incrementing the counter, but not display it.

Hope that helps.
__________________
If practice makes perfect and nobody's perfect... why practice?

Homepage: http://www.treywhite.com
Blog: http://www.treywhite.com/blog.php
Web Design Company: http://www.ewebproductions.com
 
 

Recent GIDBlogNARMY by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 07:44
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 10:53
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 11:28
Can't view pages from another machine on the Intranet aevans Apache Web Server Forum 9 14-May-2004 02:26

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:12.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.