Martin
Martin

Reputation: 485

Problems to scan many images folders

I have more than 10 sections/articles in a single pages and each section display 3 thumbs.

3 thumbs > linking > to 1 Images_Main

Images_Main = thumb1, thumb2, thumb3

Structure:

Images
  |_______ 1stSection
               |__________ Images_Main
                               |__________ img1
                               |__________ img2
                               |__________ img3


               |___________ Thumb
                               |__________ img1
                               |__________ img2
                               |__________ img3

So, I have wrote this little code, which is working fine for the first section but is not working. It does not show right thumbs &/or Images_Main for the rest of sections.

It keeps showing images from first folder, does not matter if I change: $smallSecond_dir = 'images/small225x341/ ** 2nd / 3rd / 4thTheme/ **';

Gets Images_Main:

         <h5>
         <?php
         $smallSecond_dir = 'images/small225x341/2ndTheme/';
         $scan = scandir($smallSecond_dir);
         echo '<img src="' . $small225x341_dir . $scan[2] . '" alt="image" />'; 

        ?>
        </h5>

Gets Thumbs:

<ul class="thumbs">
            <?php

           $thumbs75x75_dir = 'images/thumbs75x75/2ndTheme/';
           $scan = scandir($thumbs75x75_dir); 

           for ($i = 0; $i<count($scan); $i++) {

           if ($scan[$i] != '.' && $scan[$i] != '..') {
            if (strpos($scan[$i], '.jpg') !== false) {
            echo '
             <li>
             <a href="' . $smallSecond_dir . $scan[$i] . '">
             <img src="' . $dir . $scan[$i] . '" alt="' . $scan[$i] . '" />
             </a>
             </li>';
            }
           }
           }; 
           ?>
          </ul>

How can I scan each sections folder and show right thumb and right Images_Main?

Thanks

Upvotes: 0

Views: 119

Answers (1)

jatt
jatt

Reputation: 398

Long time ago I wrote for some needing this code ... maybe will help you

$subgalery = array();
function read_dir($dir){
    global $subgalery;       
        if(file_exists($dir)){
        $opened = opendir($dir);
        while (($file = readdir($opened)) !== false){
            if($file !== '.' && $file !== '..' && (is_dir($dir."/".$file))){
                $subgalery[$dir."/".$file] = $file;
                read_dir($dir."/".$file);
            }
        }
        closedir($opened);
}

returns array of all forlders inside folder

You can make it without global, just put it inside with array_merge and return ... it is old code

Upvotes: 1

Related Questions