-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetatlas.php
47 lines (43 loc) · 1.13 KB
/
getatlas.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
<?php
header('Content-Type: application/json');
try
{
if (!isset($_REQUEST['fname']))
throw new Exception('No file name provided');
if (!preg_match('#^(\./+)?(.*\.atlas)$#', $_REQUEST['fname'], $matches))
throw new Exception('Invalid file name');
$fname_json = $matches[2] . '.json';
if (file_exists($fname_json))
{
if (@readfile($fname_json) === false)
throw new Exception('Failed to read file');
}
else if ($fname_json == '__all__.atlas.json')
{
$res = array();
$iter = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator('.',
FilesystemIterator::KEY_AS_PATHNAME
| FilesystemIterator::SKIP_DOTS
| FilesystemIterator::FOLLOW_SYMLINKS));
foreach ($iter as $fname => $path_obj)
{
if ($path_obj->isFile() && substr($fname, -11) == '.atlas.json')
{
$obj = json_decode(file_get_contents($fname), true);
$res = array_merge($res, $obj);
}
}
$json_data = json_encode($res);
@file_put_contents($fname_json, $json_data);
echo $json_data;
}
else
{
throw new Exception('File not found');
}
}
catch (Exception $e)
{
echo json_encode(array('error' => $e->getMessage()));
}