Jump to content

Image Array


carbide20

Recommended Posts

Hi, I'm trying to write a script that reads in .png files from a folder, and displays them as links to folders with their names. ie:

 

an 'img' folder contains 'test1.png' and 'test2.png' and it would load in those images, and make them link to the folders: 'test1/' and 'test2/'

 

I got it all working (using an array so I can sort them alphabetically), but it dosent seem to be letting me check if they are .png files.

 

 

 

 

<?php
  $cols = 7; //Total Columns
  $dir = "img/sections/"; //Game Dir
  $dh = opendir($dir);
  $count = 1;
  
  while($file = readdir($dh)) {
    if($file != ".." AND $file != ".") {
      $sectionArray[] = $file;
    }
  }
  
  echo "<table cellpadding='0' cellspacing='0'><tr>";
  
  //loop through the dir
  foreach($sectionArray as $section) {
  
    $name = explode(".", $section, -1);
    $first = $name[0];
    
    // THIS IS THE PART THAT DOES NOT WORK!!!
    $last = $name[1];
    
    if ($last == "png"){
    // END PART THAT DOES NOT WORK!!!
         
      //Output everything
      echo "<td align='center' valign='top' width='" . 100 / $cols . "%'><br /><a href='sections/" . $first . "'><img src='" . $dir . $section . "' border='0'/></a></td>";  
              
      //End row, or increment count
      if($count >= $cols) {
        echo "</tr><tr>";
        $count = 1;
      } else {  
        $count++;
      }
    
    }
                        
  }


  closedir($dh);
  echo "</tr></table><br />";
?>

Link to comment
https://forums.phpfreaks.com/topic/81841-image-array/
Share on other sites

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.