add json data file
This commit is contained in:
commit
ce84d5e9ac
1
data/images.json
Normal file
1
data/images.json
Normal file
File diff suppressed because one or more lines are too long
15
docker-compose.yaml
Normal file
15
docker-compose.yaml
Normal 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
17
index.php
Normal 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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user