Image directory index


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <? $title = htmlspecialchars("Guy Fawkes Nights at EBI Campus & Cambridge 4-5.11.2008"); ?>
  2. <html>
  3. <head>
  4. <title><?= $title ?></title>
  5. <style type="text/css">
  6. body { background: #666666;color: #cccccc;font-family: tahoma, verdana, sans-serif;padding: 30px; }
  7. img { border: 1px solid #cccccc;margin-right: 30px;vertical-align:top; }
  8. h1 { font-size: 30pt;font-weight: bold;margin-bottom:50px; }
  9. div { font-size: 10pt; }
  10. span { font-size: 30pt;font-weight: bold;font-family: impact,tahoma,sans-serif;color: #888888; }
  11. a:link,a:hover,a:active,a:visited { color: #cccccc; text-decoration:underline}
  12. </style>
  13. </head>
  14. <body>
  15. <h1><?= $title ?></h1>
  16. <p><a href="../">back to list</a></p>
  17. <?
  18. // just a comment to test and remove
  19.  
  20. $cwd = opendir('.');
  21. if(!$cwd) die("can't open dir!");
  22.  
  23. $desc = array();
  24. if(file_exists('descript.ion'))
  25. foreach(file('descript.ion') as $line)
  26. if(preg_match('/^(\\S+)\\s+(.*?)\\s*$/', $line, $d))
  27. $desc[$d[1]] = $d[2];
  28.  
  29. $images = array();
  30. while($file = readdir($cwd))
  31. {
  32. if(preg_match('/\\.(jpe?g|gif|png)$/i', $file) && is_readable($file))
  33. {
  34. list($width, $height, $type) = getimagesize($file);
  35. if($width && $height)
  36. {
  37. $images[$file] = array($width, $height);
  38. }
  39. }
  40. }
  41.  
  42. $names = array_keys($images);
  43. sort($names);
  44. $k = 0;
  45. foreach($names as $img)
  46. {
  47. $i = $images[$img];
  48. ?>
  49. <p><img src="<?=$img?>" width="<?=$i[0]?>" height="<?=$i[1]?>" alt=""><span><?=++$k?></span><div><?=htmlspecialchars($desc[$img])?></div></p>
  50. <?
  51. }
  52. ?>
  53. </body>
  54. </html>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.