-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
50 lines (40 loc) · 1.32 KB
/
api.php
File metadata and controls
50 lines (40 loc) · 1.32 KB
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
<?php
//GET ALBUMS
if(empty($_GET['album'])) {
if($dir = opendir('galleries')) { //list existing albums
while($folder = readdir($dir))
if(is_dir('galleries/'.$folder) && $folder !== '.' && $folder !== '..')
$albums[] = $folder;
closedir($dir);
}
echo json_encode($albums);
}
//GET DIR
else {
$album = 'galleries/' . str_replace(array('\\','"','$'), '', $_GET['album']);
if(substr($album, -1) !== '/') $album .= '/';
$filter = isset($_GET['filter']) ? $_GET['filter'] : false;
if(!is_dir($album)) {
http_response_code(403);
exit();
}
$res = new stdClass();
$res->dirs = array();
$res->files = array();
$dir = opendir($album);
while($file = readdir($dir)) {
if($file === '.' || $file === '..') continue;
if(is_dir($album.$file)) //dir
array_push($res->dirs, (object) array("name" => $file, "mtime" => filemtime($album.$file), "size" => filesize($album.$file)));
else { //file
if($filter) {
list($x,$y,$type) = getimagesize($album.$file);
if(!$type || $type === 5 || ($filter === 'land' && $x < $y) || ($filter === 'port' && $x > $y)) continue;
}
$res->files[] = (object) array("name" => $file, "mtime" => filemtime($album.$file), "size" => filesize($album.$file), "valid" => 1);
}
}
closedir($dir);
echo json_encode($res);
}
?>