Created
May 20, 2009 20:50
-
-
Save nsuan/115086 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$def_img_url="wolf-grass.jpg"; | |
//default image to redirect to if no images exist in random dir | |
//read folder | |
$folder=opendir(getcwd()); | |
while ($file = readdir($folder)){ | |
$ext=strtolower(substr(trim($file),-4)); | |
if ($ext==".jpg"||$ext==".gif"||$ext=="jpeg"||$ext==".png") { | |
$imgs[]=$file; | |
} | |
} | |
closedir($folder); | |
if (is_array($imgs)){ | |
srand((double)microtime()*1000000); | |
do { | |
$ofile = $imgs[rand(0, count($imgs)-1)]; | |
} while($ofile == $_SERVER['HTTP_ETAG']); | |
$fp = fopen($ofile, "r"); | |
$size = getimagesize($ofile); | |
header('ETag: ' . $ofile); | |
header('Content-type: ' . $size['mime']); | |
header("Content-Length: " . filesize($ofile)); | |
fpassthru($fp); | |
}else{ | |
header ("location: $def_img_url"); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment