-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
65 lines (53 loc) · 1.92 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
// include("./private/database.php");
// function path($path){
// if($path === "/"){
// return "index.html";
// }elseif($path === "/web"){
// $json_data = file_get_contents("data.json");
// $data = json_decode($json_data, true);
// header('content-type: application/json');
// return json_decode($data);
// if(str_contains($path, "/web/")){
// $cutPos = strpos($path, "/web/");
// $num = substr($path, $cutPos);
// echo $num;
// }
// }elseif($path === "/ceevee"){
// header('Content-type: application/docx');
// return readfile("CavemanResume.docx");
// }
// }
// $json_data = file_get_contents("data.json");
// $data = json_decode($json_data, true);
// if($_SERVER["REQUEST_URI"] === "/web"){
// header('Content-Type: application/json');
// return json_encode($data);
// }elseif($_SERVER["REQUEST_URI"] === "/ceevee"){
// header('Content-type: application/docx');
// // header('Content-Disposition: attachment; filename="downloaded.docx"');
// return readfile("CavemanResume.docx");
// }
// path($_SERVER["REQUEST_URI"]);
// $path = "/web/50";
// if(str_contains($path, "/web/")){
// $cutPos = strpos($path, "/web/");
// $num = substr($path, 5);
// echo $num;
// }
$path = "/facts/dogs/50";
// Fetch JSON from thee file
$json_data = file_get_contents("data/dogfacts.json");
$data = json_decode($json_data, true);
// To check if theres an extra parameter for ammount of data to send
$num = substr($path, 12);
$response = [];
if($num > 0){
for ($i = 0; $i < $num; $i++){
$response[] = $data[rand(0, 200)];
}
}else{
$response[] = $data[rand(0, 200)];
}
echo json_encode($response, true);
?>