* */ // force image if (isset($_GET['img'])) { $f = $_GET['img']; if (file_exists($f)) { sendFile($f); } else rotatorDie(); } // get path and random image $path = ''; if (isset($_GET['path'])) { $path = $_GET['path']; } else $path = '.'; rtrim($path, '/'); if (file_exists($path)) { $files = glob($path .'/*.jpg'); if($files === false) rotatorDie(); else { $i = rand(0, count($files)-1); $f = $files[$i]; unset($files); sendFile($f); } } else rotatorDie(); /* Functions */ function getMime($ext) { switch($ext) { case 'jpg': case 'jpeg': return 'image/jpeg'; break; case 'gif': return 'image/gif'; break; case 'png': return 'image/png'; break; default: return false; break; } } function sendFile($f) { $ext = substr($f, -3, 3); $mime = getMime($ext); if ($mime === false) rotatorDie(); header("HTTP/1.1 200 OK"); header("Content-Type: $mime"); ob_start(); readfile($f); ob_end_flush(); exit; } function rotatorDie() { header("HTTP/1.1 404 Not Found"); echo '404 Not Found'; exit; } ?>