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"; 

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.