1:PHP隨機(jī)顯示圖片
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)); //設(shè)定隨機(jī)數(shù)的范圍; //根據(jù)文件類(lèi)型,設(shè)置輸出的文件類(lèi)型; 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>不存在!請(qǐng)重新設(shè)置!</b>"; ?> |
2:PHP隨機(jī)圖片
創(chuàng)建名為1到15的gif圖片,隨機(jī)調(diào)用顯示.(注意,文件名為1.gif到15.gif之間)
可用于論壇頭像,嘿嘿…
1 | <?readfile(rand(1,15).".gif");?> |