API随机获取图片代码

API随机获取图片代码

<?php
    $counter = intval(file_get_contents("counter.dat"));
     $_SESSION['#'] = true;
     $counter++;
     $fp = fopen("counter.dat","w");
     fwrite($fp, $counter);
     fclose($fp);
 ?>
<?php
$filename = "img.txt";
if(!file_exists($filename)){
	die('文件不存在');
}


$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){

case 'json':
	header('Content-type:text/json');
	die(json_encode(['pic'=>$pic]));

default:
	die(header("Location: $pic"));
}

上传你的服务器或者主机空间,命名随意后缀为.php

并在同级目录上传一个为img.txt后缀的文件

PS:一个图片链接链接占一行

访问形式为 http(s)://你的域名/你的命名.php

例如 https://bsgun.cn/m.php

输出为图片

 » 链接: https://www.sxpik.com/404.html

 » 本文来自热心的夹友 Niuma 提供。

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索