Posted By

kyokutyo on 03/22/08


Tagged

list image glob picture


Versions (?)

Who likes this?

8 people have marked this snippet as a favorite

basicmagic
Wiederkehr
paullorentzen
fackz
Mithun
nb109
shawntorres
joethermal


Display pictures in the directory


 / Published in: PHP
 

[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

  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
Posted By: shawntorres on August 17, 2009

Hi, I am a newbie, This is a handy script, I was wondering if and how I could modify this script to work with another directory?

Posted By: shawntorres on August 17, 2009

Hi, I am a newbie, This is a handy script, I was wondering if and how I could modify this script to work with another directory?

Posted By: shawntorres on January 29, 2010

Yes. yes you can point to another location shawn, the answer is elementary silly noob. modified script:

<ul>

  <li>
Posted By: shawntorres on January 29, 2010

<ul>

  <li>
Posted By: shawntorres on January 29, 2010

http://snipplr.com/view/27334/modified-display-pictures-in-the-directory-by-kyokutyo/

You need to login to post a comment.