randomimg.php
<?php
//存有链接的文件名
$filename = "randomimg.txt";
//从文本获取链接
$pics = [];
$fs = fopen($filename, "r");
while(!feof($fs)){
$line=trim(fgets($fs));
if($line!=''){
array_push($pics, $line);
}
}
//从数组随机获取链接
$pic = $pics[array_rand($pics)];
//返回指定格式
$type=$_GET['type'];
switch($type){
//JSON返回
case 'json':
header('Content-type:text/json');
die(json_encode(['pic'=>$pic]));
default:
die(header("Location: $pic"));
}
randomimg.txt
https://imglf4.lf127.net/img/K0RRZklSb1VXbUttV0g1Z3VteWNLL0hhcHJFalFMMFlFT0M0ZGFndzFXQXZVSnJBaG5YMHl3PT0.jpg
https://imglf5.lf127.net/img/K0RRZklSb1VXbUttV0g1Z3VteWNLNTN1RWZHaWV3T3pya0x5dkFrWFBlTFRacWg4U2dvVjJBPT0.jpg
https://imglf3.lf127.net/img/K0RRZklSb1VXbUttV0g1Z3VteWNLM0R4K2crVHJiTUtyTlp3WXN4TEpIOVJOSFdVSXdPK1NRPT0.jpg
https://imglf4.lf127.net/img/K0RRZklSb1VXbUttV0g1Z3VteWNLMlBabm1GT091TldUU3JVTlMxMExlZ1FBajlGVzA5N2d3PT0.jpg
https://imglf3.lf127.net/img/K0RRZklSb1VXbUttV0g1Z3VteWNLNjJyUXBUMjBFUnV0MzJITEZQdXpVYXlzM3R3Q0lqQTJBPT0.png
https://imglf5.lf127.net/img/K0RRZklSb1VXbUttV0g1Z3VteWNLeHh3a0V2SmpzMlB5enRIMk51NDI3eGJZT2JRR1ZWSlFRPT0.jpg
https://imglf3.lf127.net/img/K0RRZklSb1VXbUttV0g1Z3VteWNLK0ZxUW5JbGVVL0RVaXgrcDNIN0RheHpKWjN4QjVZd2pRPT0.jpg
https://imglf4.lf127.net/img/K0RRZklSb1VXbUp5Rm9BWHI2UXMxcVdzelFIVjNrOHVrenNzN2xnRG5ieTdNdStSazhqUEdBPT0.jpg
https://imglf3.lf127.net/img/K0RRZklSb1VXbUpTUXFGVWlBQ3FzYU1kY0ZWZi9MU3JSQmlJU3J1OCt6aGZVdVZ0TUNHblZ3PT0.png
https://imglf3.lf127.net/img/K0RRZklSb1VXbUpTUXFGVWlBQ3FzZHlwNSt1NlZObUtuMThBQTNmMzFCVU5KckNxVnZET2lnPT0.jpg
https://imglf5.lf127.net/img/K0RRZklSb1VXbUpTUXFGVWlBQ3FzUlRXbm5SeHdyMks3QVFhbTRWdmVEVll5TTQxS2Q0TDZRPT0.jpg
https://imglf4.lf127.net/img/K0RRZklSb1VXbUpTUXFGVWlBQ3FzYkdtaE1GN2dYQTFJcVhKbWRkL1N6SXpLQkVSMDA3Y25RPT0.jpg
https://imglf4.lf127.net/img/K0RRZklSb1VXbUpTUXFGVWlBQ3FzZm56UE5DQm1wQTlqNXVMN2xEdTQxcFAzS2NjN1k1K2NnPT0.jpg
https://imglf3.lf127.net/img/K0RRZklSb1VXbUpTUXFGVWlBQ3FzZm1KbUZ2aFFaNGtZdEJYejJ0cTk0aUJNRGN6bkRzdDZRPT0.jpg
显然易见地,访问 randomimg.php 即可随机转到 randomimg.txt 文件中的图片地址。
randomimg.php 的默认配置下,这两个文件需要在同一目录。 作者:rap李恵龙 https://www.bilibili.com/read/cv18641050 出处:bilibili