说明:
新建一个index.php文件,将代码放置在内,上传到云主机在新建一个img.txt文本,里面放置图片链接,一行一个链接,上传到主机,放置相同目录下。
代码如下:
<?php
//存有美图链接的文件名img.txt
$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){
//JSON返回
case \'json\':
header(\'Content-type:text/json\');
die(json_encode([\'pic\'=>$pic]));
default:
die(header(\"Location: $pic\"));
}
?>
感谢您的来访,获取更多精彩文章请收藏本站。

© 版权声明
THE END
暂无评论内容