Guest
Public paste!

mroddball

By: a guest | Sep 29th, 2009 | Syntax: PHP | Size: 1.55 KB | Hits: 51 | Expires: Never
Copy text to clipboard
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2.   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4.  
  5. <head>
  6.         <title>Gallery</title>
  7.         <meta http-equiv="content-type" content="text/html;charset=utf-8" />
  8.         <style type="text/css">
  9.                 table {margin: 1px auto;border: 1px solid black;background-color: #DCDCDC;}
  10.                 img {border: 1px solid #778899;margin: 7px}
  11.                 body {background-color: #FFFFE0;}
  12.         </style>
  13. </head>
  14.  
  15. <body>
  16.         <table>
  17.  
  18.  
  19.                 <tr>
  20.                
  21.                 <?php
  22.                 //Only files with these extensions
  23.                 $accept_ext=array("JPG","TIFF","PNG");
  24.                 $how_many_images_in_row=4;
  25.                 $i=0;
  26.                 $file_list=array();
  27.                 if ($handle = opendir('.')) {
  28.                          while (false !== ($file = readdir($handle))) {
  29.                                  if ($file != "." && $file != "..") {
  30.                                          $temp=explode(".",$file);
  31.                                          if(in_array(strtoupper($temp[count($temp)-1]),$accept_ext)){
  32.                                                 array_push($file_list,$file);
  33.                                          }
  34.                                  }
  35.                          }
  36.                          //It's better to sort it by file name, usually they come
  37.                          // out in alphabetical order, but sometimes they don't...
  38.                          sort($file_list);
  39.                          foreach($file_list as $file){
  40.                                                  ?>
  41.                                                  
  42.                         <td><a href="<?=$file?>"><img alt="<?=$file?>" src="thumb/<?=$file?>"/></a></td>
  43.                                  
  44.                                                  <?php
  45.                                          $i++;
  46.                                          if($i!=count($file_list) && !($i%$how_many_images_in_row)){
  47.                                                  ?>
  48.                                        
  49.                 </tr>
  50.                 <tr>
  51.                                                                          
  52.                                                  <?php
  53.                                          }elseif($i==count($file_list)){
  54.                                                 ?>
  55.  
  56.                 </tr>
  57.                        
  58.                                                 <?php
  59.                                          }
  60.                          }
  61.                          closedir($handle);
  62.                 }
  63.                 ?>
  64.                
  65.         </table>
  66. </body>
  67. </html>