1:PHP随机显示图片
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <?php /* * Author: http://www.yox.net.ru */ $url = "./images"; //注意:图片文件夹路径,不可含有'/'; $files = array(); if(false !== ($handle = @opendir($url))) { while($file = readdir($handle)) { if(($file !== ".")&&($file !== "..")) { if((substr($file,-3) == "gif") || (substr($file,-3) == "jpg") || (substr($file,-3) == "png")) $files[count($files)] = $file; } } closedir($handle); $random = rand(0,(count($files)-1)); //设定随机数的范围; //根据文件类型,设置输出的文件类型; if(substr($files[$random],-3) == "gif") header("Content-type:image/gif"); elseif(substr($files[$random],-3) == "jpg") header("Content-type:image/jpeg"); elseif(substr($files[$random],-3) == "png") header("Content-type:image/png"); readfile("$url/$files[$random]"); //读文件,显示图片; }else echo "<b>图片目录<font color=red>$url</font>不存在!请重新设置!</b>"; ?> |
2:PHP随机图片
创建名为1到15的gif图片,随机调用显示.(注意,文件名为1.gif到15.gif之间)
可用于论坛头像,嘿嘿…
1 | <?readfile(rand(1,15).".gif");?> |