views:

56

answers:

2

Hi,

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

+1  A: 

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

jatt
A: 

It's hard to tell because it depends on your operating environment and surrounding code.

You need to narrow down the exact cause why the images are not displayed, step by step.

First of all, test if PHP "sees" the directories you are attempting to access and echo the results.

$thumbs75x75_dir = 'images/thumbs75x75/2ndTheme/';
echo file_exists($thumbs75x75_dir) ? "The directory $thumbs75x75_dir exists" : "$thumbs75x75_dir is not there";

Look at the results. If PHP doesn't see the directory, check spelling and case. Verify that the relative path to the script is correct. When the script sees the directory and things are still not working, check if the script is actually seeing what you think it sees.

$scan = scandir($thumbs75x75_dir);  
echo '<pre>' . print_r($scan, true) . '</pre>';

The code above will give an internal view of the array returned by the scandir function. Verify that you are accessing the right elements. If the directory exists but the scandir result is empty, you have obviously forgotten to put the thumbnails where you are reading them.

If the contents of $scan is correct and things are still not working, take a look at the for loop. Echo test strings at various places to see which if block you reach. Etc. You get the idea..

Saul
What? It doesn't find the directory because the directory does not exist. If you don't understand the file system and the way PHP interprets paths then I'm afraid my advice is beyond you.
Saul