jmyeom

rotate.php

Jan 13th, 2012
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. can be used normally and will loop though all images, under all sub folders, or apply to board specific and will only show ones under that board sub folder
  2.  
  3.  
  4. <img src="rotate.php" alt="Header" width="400" height="100" />
  5.  
  6. or
  7.  
  8. <img src="rotate.php?board={$board.name}" alt="Header" width="400" height="100" />
  9.  
  10.  
  11.  
  12. i.e, normally, it will loop though everything set as the folder path...
  13.  
  14. in folder images , i have subfolders: b,sugg,derp,magic all with images in them
  15.  
  16. if i use the first example, it all pick a random image from all of the subfolders
  17.  
  18. if i set the secand one, it will only look in the subfolder that has the same name as the board....
  19.  
  20.  
  21.  
  22. hope it helps...
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31. make a file called rotate.php (or anything else)
  32. put this inside it:
  33.  
  34.  
  35. <?php
  36. //dont change these, dont even think about adding "bmp" support, it will rape you in the ass
  37. $EXTENSIONS = 'gif,jpg,jpeg,png';
  38. if(isset($_GET["board"])?$folder = 'images/'.$_GET["board"]."/":$folder = 'images/');
  39. $fileList = array();
  40. $handle = opendir($folder);
  41. while ( false !== ( $file = readdir($handle) ) ) {
  42. $file_info = pathinfo($file);
  43. if ($file != "." && $file != "..") {
  44. if(strstr($file, ".") && strstr($EXTENSIONS,strtolower($file_info['extension']))){
  45. $fileList[] = $file;
  46. }elseif(!isset($_GET["board"])){
  47. $handle2 = opendir($folder.$file);
  48. while ( false !== ( $file = readdir($handle2) ) ) {
  49. $file_info = pathinfo($file);
  50. if ($file != "." && $file != "..") {
  51. if(strstr($file, ".") && strstr($EXTENSIONS,strtolower($file_info['extension']))){
  52. $fileList[] = $file;
  53. }
  54. }
  55. }
  56. }
  57. }
  58. }
  59. closedir($handle);
  60. if(count($fileList) > 0 ? $img = $folder.$fileList[rand(0, count($fileList)-1)] : die());
  61. $imageInfo = pathinfo($img);
  62. header ('Content-type: image/'.($imageInfo['extension'] == 'jpg' ? 'jpeg' : $imageInfo['extension']));
  63. readfile($img);
  64. ?>
Advertisement
Add Comment
Please, Sign In to add comment