Jump to content

Can't seem to get a list of folders within, rather than all elements in a folder


djkirstyjay

Recommended Posts

I have a piece of code that I am trying to get the folders only within a specific images folder, as there's an index.htm file that I can't delete and I don't want it used in my code.

 

I know I have to use is_dir, but for the life of me, I can't seem to put it in the correct place so that it works.

 

Can anyone advise to put me out of my misery?

 

Thanks in advance!

 

$thumbs = "../thumbs/"; # Location of thumbs 
$images = "images/"; # Location of images 
$cols   = 5; # Number of columns to display 

if ($handle = opendir($images)) { 
   while (false !== ($file = readdir($handle))) {
    
   
   if ($file != "." && $file != ".." && is_dir($file)) {
           $files[] = $file;
       } 
   } 
   closedir($handle); 
} 
$colCtr = 0; 

echo "<table>
<tr>
  <tr>"; 
rsort($files);
foreach($files as $file) 
{ 
$fldrno = ereg_replace("folder", "", $file);
  if($colCtr %$cols == 0) 
    echo "</tr><tr>"; 
  echo "<td>
  		<a href=\"" . $images . $fldrno . "/index.html\">
  		<img src=\"" . $thumbs . $fldrno . "/thumb.jpg\" alt=\"" . $alt . "\" />
  		</a>
	</td>"; 
  $colCtr++; 
} 

echo "</table>" . "\r\n"; 

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.