方法1:在img文件夹下放N张图片文件,随机读取
<?php
header('Content-Type: image/png');
$img_array = glob('img/*.{gif,jpg,png,jpeg}',GLOB_BRACE);
if(count($img_array) == 0)
die('没找到图片文件。请先上传一些图片到 '.dirname(__FILE__).'/img/ 文件夹');
exit(file_get_contents($img_array[array_rand($img_array)]));
?>
方法2:将图片链接全部放到imgurl.txt文件里,一行一个,随机输出其中一个
<?php
header('Content-Type: image/png');
$txt=file_get_contents('imgurl.txt');
$array=explode("\n",$txt);
$url=trim($array[array_rand($array)]);
exit(header("Location:".$url));
//exit(file_get_contents($url)); ?>