RandomImg/index.php
2021-04-05 17:31:24 +08:00

17 lines
490 B
PHP

<?php
error_reporting(0);
$file_path = "data/images.json";
if(file_exists($file_path)){
$fp = fopen($file_path,"r");
$str = fread($fp,filesize($file_path));
$res = json_decode($str,true);
$randNum = rand(0,sizeof($res)-1);
$url = $res[$randNum]['url'];
$name = $res[$randNum]['name'];
if($_GET['return'] == 'json'){
$arr = ['code' => 0,'url' => $url,'name' => $name];
echo json_encode($arr);
} else {
header('Location:'.$url);
}
}