PHP随机图片API

在网络上偶然找到一个随机调用图片输出的API,这里分享一下源码。

<?php
//存有链接的文件名,这里是存放图片链接的txt文件,一行一个链接,可置于api的同一目录
$filename = "piclist.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"));
}

来源:https://img.yy.wiki/acg/

本文采用 CC BY-NC-SA 3.0 Unported 许可,转载请以超链接注明出处。
原文地址:PHP随机图片API 作者:松鼠小
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
Source: Telegram @AmashiroNatsukiEars_NoWord Sticker
Source: Github @zhheo/Sticker-Heo
Source: github.com/k4yt3x/flowerhd
颜文字
AmashiroNatsukiEars
Heo
小恐龙
花!
上一篇
下一篇
  1. 1 Rain after Summer 羽肿
  2. 2 潮鳴り VISUAL ARTS / Key
  3. 3 Inspire Capo Productions
  4. 4 Hyacinth July
  5. 5 My Soul July
  6. 6 Best Moments (feat. Kondor) Blazo/Kondor
  7. 7 Lost Love (Instrumental) Lunnna/Janey杰尼
  8. 8 风居住的街道(Piano ver) (翻自 磯村由紀子) 饭碗的彼岸
  9. 9 Beyond The Memory July
  10. 10 メインテーマ「永遠の一瞬」 伊藤賢治
  11. 11 Journey Capo Productions
  12. 12 Flower Dance DJ Okawari
  13. 13 Righteous Path Blazo
  14. 14 いのちの名前 広橋真紀子
  15. 15 花火が瞬く夜に 羽肿
  16. 16 记得 风潮音乐
  17. 17 Encouragement Kondor
  18. 18 Rise - Epic Music John Dreamer
  19. 19 A Little Story Valentin
  20. 20 City 羽肿
  21. 21 《夜色钢琴曲》kiss the rain(翻自 YIRUMA) 赵海洋
  22. 22 Moon Flow Nomak
  23. 23 River Flows in You Yiruma
  24. 24 白昼之夜 林隆璇
  25. 25 LOVIN' YOU 押尾コータロー
  26. 26 ALONE ON THE WAY Pianoboy高至豪
  27. 27 Intro The xx
  28. 28 Somewhere July
  29. 29 我在那一角落患过伤风(钢琴版) 群星
  30. 30 Rainy Day Reminiscence Soulostar
  31. 31 Refrain 阿南亮子
  32. 32 STEPPING ON THE RAINY STREET 群星
  33. 33 Angel and Devil Elyonbeats
  34. 34 Butterfly Waltz Brian Crain
  35. 35 Mallow Flower Otokaze
  36. 36 The truth that you leave Pianoboy高至豪
  37. 37 canon in d Brian Crain
  38. 38 めぐる季節 久石譲/奥户巴寿
  39. 39 拥有 几米
  40. 40 碎月雨中奏 iw ix
  41. 41 Always With Me 木村弓/奥户巴寿
  42. 42 Everlasting Truth (Album Mix) re:plus
  43. 43 The promise Secret Garden
  44. 44 Luv Letter DJ Okawari
Rain after Summer - 羽肿
00:00 / 00:00

Loading