You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.5 KiB

6 years ago
  1. <?php
  2. header('Cache-Control: no-cache, must-revalidate');
  3. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  4. header('Content-type: application/json');
  5. $images = array();
  6. function scan_dir($dir) {
  7. $ignored = array('.', '..', '.svn', '.htaccess');
  8. $files = array();
  9. foreach (scandir($dir) as $file) {
  10. if (in_array($file, $ignored)) continue;
  11. $files[$file] = filemtime($dir . '/' . $file);
  12. }
  13. arsort($files);
  14. $files = array_keys($files);
  15. return ($files) ? $files : false;
  16. }
  17. function imagelist($dir)
  18. {
  19. global $images;
  20. //$stuffs = scandir($dir);
  21. $stuffs = scan_dir($dir);
  22. for ($i = 0; $i < sizeof($stuffs); $i++)
  23. {
  24. $farr = explode('.', $stuffs[$i]);
  25. if ($stuffs[$i] != '.' && $stuffs[$i] != '..' && $farr[0] != 'thumb')
  26. if (is_dir($stuffs[$i]))
  27. imagelist($dir.'/'.$stuffs[$i]);
  28. elseif (in_array(end($farr), array('gif', 'png', 'jpg', 'jpeg')))
  29. {
  30. // PATHS
  31. $outdir = '/data/'.ltrim($dir, './').'/';
  32. $img = $dir.'/'.$stuffs[$i];
  33. $thumb = $dir.'/thumb.'.$stuffs[$i];
  34. // THUMBNAIL
  35. if (!file_exists($thumb))
  36. {
  37. $cthumb = new Imagick($img);
  38. $cthumb->cropThumbnailImage(260, 260);
  39. $cthumb->writeImage($thumb);
  40. $cthumb->destroy();
  41. }
  42. // ADD TO LIST
  43. array_push($images, array(
  44. 'image' => $outdir.rawurlencode($stuffs[$i]),
  45. 'thumb' => $outdir.'thumb.'.$stuffs[$i],
  46. 'folder' => ltrim($dir, './')
  47. ));
  48. }
  49. }
  50. }
  51. imagelist('./uploads');
  52. foreach(glob('./uploads/*', GLOB_ONLYDIR) as $dir)
  53. imagelist($dir);
  54. echo str_replace('\/', '/', json_encode($images));