Advertisement
Guest User

Untitled

a guest
Jul 27th, 2015
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.58 KB | None | 0 0
  1. <?php
  2. header('Content-Type: text/javascript; charset=UTF-8');
  3.  
  4. // Images
  5. $imageFolder = '/Shared/';
  6. $imageTypes = '{*.jpg,*.JPG,*.jpeg,*.JPEG,*.png,*.PNG,*.gif,*.GIF}';
  7.  
  8. // Switch these depending on how you want sorted
  9. $sortByImageName = false;
  10. $newestImagesFirst = true;
  11.  
  12. // Add images to array
  13. $images = glob($imageFolder . $imageTypes, GLOB_BRACE);
  14.  
  15. // Sort
  16. if ($sortByImageName) {
  17.     $sortedImages = $images;
  18.     natsort($sortedImages);
  19. } else {
  20.     $sortedImages = array();
  21.     $count = count($images);
  22.     for ($i = 0; $i < $count; $i++) {
  23.         $sortedImages[date('YmdHis', filemtime($images[$i])) . $i] = $images[$i];
  24.     }
  25.     if ($newestImagesFirst) {
  26.         krsort($sortedImages);
  27.     } else {
  28.         ksort($sortedImages);
  29.     }
  30. }
  31.  
  32. // Html piece
  33. writeHtml('<ul class="ins-imgs">');
  34. foreach ($sortedImages as $image) {
  35.     $name = 'Image name: ' . substr($image, strlen($imageFolder), strpos($image, '.') - strlen($imageFolder));
  36.     $lastModified = '(last modified: ' . date('F d Y H:i:s', filemtime($image)) . ')';
  37.     writeHtml('<li class="ins-imgs-li">');
  38.     writeHtml('<div class="ins-imgs-img"><a name="' . $image . '" href="#' . $image . '">');
  39.     writeHtml('<img src="' . $image . '" alt="' . $name . '" title="' . $name . '">');
  40.     writeHtml('</a></div>');
  41.     writeHtml('<div class="ins-imgs-label">' . $name . ' ' . $lastModified . '</div>');
  42.     writeHtml('</li>');
  43. }
  44. writeHtml('</ul>');
  45. writeHtml('<link rel="stylesheet" type="text/css" href="ins-imgs.css">');
  46.  
  47. function writeHtml($html) {
  48.     echo "document.write('" . $html . "');\n";
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement