add json data file

This commit is contained in:
rainerosion 2021-04-05 17:31:24 +08:00
commit ce84d5e9ac
3 changed files with 33 additions and 0 deletions

1
data/images.json Normal file

File diff suppressed because one or more lines are too long

15
docker-compose.yaml Normal file
View File

@ -0,0 +1,15 @@
version: '3'
services:
phpweb:
container_name: php73-random-images
image: phpstorm/php-73-apache-xdebug-27
ports:
- 80:80
volumes:
- ./:/var/www/html
environment:
XDEBUG_CONFIG: remote_host=127.0.0.1
networks:
- randomImg
networks:
randomImg:

17
index.php Normal file
View File

@ -0,0 +1,17 @@
<?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);
}
}