Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- <img src="rotate.php" alt="Header" width="400" height="100" />
- or
- <img src="rotate.php?board={$board.name}" alt="Header" width="400" height="100" />
- i.e, normally, it will loop though everything set as the folder path...
- in folder images , i have subfolders: b,sugg,derp,magic all with images in them
- if i use the first example, it all pick a random image from all of the subfolders
- if i set the secand one, it will only look in the subfolder that has the same name as the board....
- hope it helps...
- make a file called rotate.php (or anything else)
- put this inside it:
- <?php
- //dont change these, dont even think about adding "bmp" support, it will rape you in the ass
- $EXTENSIONS = 'gif,jpg,jpeg,png';
- if(isset($_GET["board"])?$folder = 'images/'.$_GET["board"]."/":$folder = 'images/');
- $fileList = array();
- $handle = opendir($folder);
- while ( false !== ( $file = readdir($handle) ) ) {
- $file_info = pathinfo($file);
- if ($file != "." && $file != "..") {
- if(strstr($file, ".") && strstr($EXTENSIONS,strtolower($file_info['extension']))){
- $fileList[] = $file;
- }elseif(!isset($_GET["board"])){
- $handle2 = opendir($folder.$file);
- while ( false !== ( $file = readdir($handle2) ) ) {
- $file_info = pathinfo($file);
- if ($file != "." && $file != "..") {
- if(strstr($file, ".") && strstr($EXTENSIONS,strtolower($file_info['extension']))){
- $fileList[] = $file;
- }
- }
- }
- }
- }
- }
- closedir($handle);
- if(count($fileList) > 0 ? $img = $folder.$fileList[rand(0, count($fileList)-1)] : die());
- $imageInfo = pathinfo($img);
- header ('Content-type: image/'.($imageInfo['extension'] == 'jpg' ? 'jpeg' : $imageInfo['extension']));
- readfile($img);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment