• 折腾
  • 使用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    $id=rand(1,5);    $image[1]='图片链接';    $image[2]='图片链接';    $image[3]='图片链接';    $image[4]='图片链接';    $image[5]='图片链接';    header("location:$image[$id]");    ?>