PHP 随机图像实现的代码超级简单,短短四行就搞定了:0 H+ Y3 Y( v J& m5 R- }* t
<?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)]));
?> 以上的代码会查找 images 目录下的所有图片,并随机挑选出一张显示出来。$ z8 ~6 n9 S' P$ a' g9 Y% C
|