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