在服务器php环境下,随便建个目录(如photo),再把下面的代码复制做成index.php放到photo文件夹内,然后再在里面再建个images文件夹,把自己的壁纸靓照等喜欢的图片统统都放进去,就可以随机浏览展示images文件夹内的所有图片了,地址格式如www.abc.com/photo再次打开或刷新即可随即展示每张图片。
<?php
header('Cache-Control:no-cache,must-revalidate');header('Pragma:no-cache');header("Expires:0");header("Access-Control-Allow-Origin:*");
//开始处理请求输出数据,先得到当前文件夹中images文件夹里所有指定类型图片的数组
$rand=rand(0,1);
if($rand){
$localurl="images/*.{jpg,png,gif,bmp,tif,tga,svg,webp}";
}else{
$localurl="images/*.{jpg,png,gif,bmp,tif,tga,svg,webp}";
}
$img_array=glob($localurl,GLOB_BRACE);
//从数组中选择一个随机图片并获取图片的地址
$img=array_rand($img_array);
$imgurl=$img_array[$img];
$https=isset($_GET["https"])?$_GET["https"]:1;
if($https == "true"){
$imgurl='https://'.$_SERVER['SERVER_NAME'].