Page 1 of 1

displaying dir contents

Posted: Thu Nov 11, 2004 4:14 pm
by liquid
Im trying to display a dir's contents. Which is working fine except that it is also displaying the dir structure:

example:
. <--- do not want this to display
.. <--- do not want this to display
first file
second file
etc...

How do I get rid of those first entries????

Code: Select all

<?php
$dir = "fileupload/uploads/".$row['cname']."/";
				if (is_dir($dir)) {
  					 if ($dh = opendir($dir)) {
							do{  
						 	echo "<a href="$dir$file" target="_blank">";
          					 echo $file;
							 echo "</a>";
							 echo "<br>";
							
							}while(($file = readdir($dh)) !== false);
      					 
      				 closedir($dh);
   					}
				}

Code: Select all

<?php
?>
?>

Thanks in advance!
liquid

Posted: Thu Nov 11, 2004 4:17 pm
by timvw
just make sure the file does not equal '.' or '..'

Posted: Thu Nov 11, 2004 4:24 pm
by rehfeld

Code: Select all

<?php

if ($handle = opendir($dir)) {
    while (false !== ($filename = readdir($handle))) {

        if ($filename !== '.' && $filename !== '..') {
           echo $filename;
        }

    }
    closedir($handle);
}

?>

Posted: Thu Nov 11, 2004 4:31 pm
by liquid
OMG...duh.. I cant believe I didnt think of that! Time to go home. :oops:

Thanks much for the quick reply!!