|
Post by Jacob on Jun 12, 2009 14:30:13 GMT -5
This code is useful if you have some avatars to use on a forum, but can't decide which one to use. Create a directory called avatars with your images in it (jpg, png, or gif), and place this script one level above it. Then put in the URL to the script as the URL to your avatar. <?php $dir = 'avatars'; $dh = opendir($dir); $files = array(); while($file = readdir($dh)) { if(is_file($dir.'/'.$file) && $file{0} != '.') { $type = substr($file, strpos($file, ".") + 1); switch($type) { case 'jpg': $header = 'jpg'; break; case 'png': $header = 'png'; break; case 'gif': $header = 'gif'; break; } $files[] = array($file, $header); } } $num = round(rand(1, count($files))) - 1; $random = $files[$num][0]; header('Content-type: image/'.$files[$num][1]); include($dir.'/'.$random); If you liked this article, why not join TheCoders?
|
|