Display pictures in the directory


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

[directory]
├index.php //this snippet
├imageA.jpg
├imageB.gif
â””imageC.png

This snipet displays the thumbnail of the picture file that exists in the
same directory.
When the thumbnail image is clicked, the original size image is displayed.

options:
filetype, width, height, pagetitle


Copy this code and paste it in your HTML
  1. <?php
  2. $fileTypes = array('jpg','jpeg','gif','png');
  3. $width = 100;
  4. $height = 100;
  5. $pageTitle = "Pictures";
  6.  
  7. // *************************************************************
  8.  
  9. $f = join(',*.', $fileTypes);
  10. $f = '*.'.$f;
  11. $height += 20;
  12. ?>
  13. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  14. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  15. <head>
  16. <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  17. <title><?php echo $pageTitle; ?></title>
  18. <style type="text/css">
  19. <!--
  20. * { margin:0; padding:0; }
  21. h1 { background:#eee; font-weight:normal; padding:3px 5px; font-size:medium; }
  22. ul { margin-top:10px; list-style:none; }
  23. ul li { width:<?php echo $width; ?>px; height:<?php echo $height; ?>px; float:left; padding:5px; overflow:hidden; margin-bottom:10px; }
  24. ul li span { height:20px; font-size:medium; font-style:italic; }
  25. ul li a img { width:<?php echo $width; ?>px; border:dotted 1px #ddd; }
  26. -->
  27. </style>
  28. </head>
  29. <body>
  30. <h1><?php echo $pageTitle; ?></h1>
  31. <ul>
  32. <?php $loop = 1; foreach (glob("{".$f."}", GLOB_BRACE) as $fileName) { ?>
  33. <li>
  34. <span><?php echo $loop; ?></span>
  35. <a href="<?php echo $fileName; ?>" target="_blank"><img alt="<?php echo $fileName; ?>" src="<?php echo $fileName; ?>" /></a>
  36. </li>
  37. <?php $loop++; } ?>
  38. </ul>
  39. </body>
  40. </html>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.