PHP随机图片源码

180it 2019-11-01 PM 1848℃ 0条

就是随机图片,那么这个随机图片是怎么实现的呢?其实很简单,几行简单的代码就能实现:
php 文件:

<?php
if(file_exists("./picList.txt"))
$picList_arr = explode("\n",file_get_contents("./picList.txt"));
@$s = empty($_GET['s'])?"large":$_GET['s'];
$imgUrl = str_replace("large",$s,$picList_arr[rand(0,count($picList_arr)-1)]);
header('Location: '.$imgUrl);
还需要一个 txt 文件(picList.txt)用来储存图片地址:

http://wx4.sinaimg.cn/large/0072WRWsly1fzlkoe0asmj31hc0zkdo5.jpg
http://wx2.sinaimg.cn/large/0072WRWsly1fzlkoeioegj32tc1l0kjl.jpg
http://wx3.sinaimg.cn/large/0072WRWsly1fzlkof2k9bj31hc0u0qv5.jpg
http://wx4.sinaimg.cn/large/0072WRWsly1fzlkofjb14j31hc0u01kx.jpg
http://wx1.sinaimg.cn/large/0072WRWsly1fzlkofzumbj31hc0u0409.jpg
http://wx2.sinaimg.cn/large/0072WRWsly1fzlkogb8j9j31hc0u00y2.jpg
http://wx3.sinaimg.cn/large/0072WRWsly1fzlkogt3fsj31hc0u0e81.jpg
http://wx4.sinaimg.cn/large/0072WRWsly1fzlkoh6kq0j31hc0u0whz.jpg
http://wx2.sinaimg.cn/large/0072WRWsly1fzlkohhkznj31hc0u0jvc.jpg
http://wx3.sinaimg.cn/large/0072WRWsly1fzlkohvi2zj31hc0u0aer.jpg
http://wx1.sinaimg.cn/large/0072WRWsly1fzlkoi9rrgj31hc0u0dlv.jpg
http://wx3.sinaimg.cn/large/0072WRWsly1fzlkoitmiaj31hc0tzwkx.jpg
http://wx1.sinaimg.cn/large/0072WRWsly1fzlkojg8t3j31hc0u0gn5.jpg
http://wx2.sinaimg.cn/large/0072WRWsly1fzlkok31jdj31hc0u0jv4.jpg
http://wx1.sinaimg.cn/large/0072WRWsly1fzlkojsfqcj31hc0u0wlu.jpg
http://wx3.sinaimg.cn/large/0072WRWsly1fzlkolcnj6j31hc0u0n69.jpg
http://wx3.sinaimg.cn/large/0072WRWsly1fzlkoksbp8j31hc0u07am.jpg
http://wx4.sinaimg.cn/large/0072WRWsly1fzlkolok1sj31hc0u0zqr.jpg
http://wx4.sinaimg.cn/large/0072WRWsly1fzlkom1ydcj31hc0u03zv.jpg
http://wx3.sinaimg.cn/large/0072WRWsly1fzlkommfmtj31hc0u0782.jpg
http://wx2.sinaimg.cn/large/0072WRWsly1fzlkon9o60j31hc0u00zl.jpg

支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

PHP随机图片源码