
之前发过一篇PHP简单实现一言 / 随机一句功能,既然随机的文字有了,随机图像当然不能落下。
PHP随机图像实现的代码超级简单,短短四行就搞定了:
<?php
$img_array = glob('images/*.{gif,jpg,png,jpeg,webp,bmp}', GLOB_BRACE);
if(count($img_array) == 0) die('没找到图片文件。请先上传一些图片到 '.dirname(__FILE__).'/images/ 文件夹');
header('Content-Type: image/png');
echo(file_get_contents($img_array[array_rand($img_array)]));
?>    	标签: php
 
    		



 
 
                 
 
                 
 
                 
 
                 
 
                 
 
                
还木有评论哦,快来抢沙发吧~