-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtool-load-file-json.php
More file actions
137 lines (132 loc) · 3.15 KB
/
tool-load-file-json.php
File metadata and controls
137 lines (132 loc) · 3.15 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
include_once dirname(__FILE__)."/functions.php";
include_once dirname(__FILE__)."/auth.php";
include dirname(__FILE__)."/conf.php";
if($cfg->authentification_needed && !$userlogin)
{
exit();
}
$dir2 = path_decode(kh_filter_input(INPUT_GET, 'dir'), $cfg->rootdir);
if(!is_dir($dir2)){
$dir2 = path_decode('base', $cfg->rootdir);
}
$arrfile2 = array();
$arrfile = array();
$arrdir = array();
if(file_exists($dir2))
{
if($handle = opendir($dir2))
{
$i=0;
while (false !== ($ufile = readdir($handle)))
{
$fn = "$dir2/$ufile";
if($ufile == "." || $ufile == ".." )
{
continue;
}
$filetype = filetype($fn);
unset($obj);
$obj = array();
if($filetype=="file")
{
$ft = getMIMEType($fn);
$obj['url'] = $cfg->rooturl.'/'.substr(path_encode($fn, $cfg->rootdir),5);
//$obj['path'] = path_encode($fn, $cfg->rootdir);
//$obj['location'] = path_encode(dirname($fn), $cfg->rootdir);
$obj['name'] = basename($fn);
$fs = filesize($fn);
$obj['filesize'] = $fs;
/*
if($fs>=1048576)
{
$obj['size'] = number_format($fs/1048576, 2, '.','').'M';
}
else if($fs>=1024)
{
$obj['size'] = number_format($fs/1024, 2, '.','').'K';
}
else
{
$obj['size'] = $fs;
}
*/
$obj['type'] = $ft->mime;
//$obj['extension'] = $ft->extension;
//$obj['permission'] = substr(sprintf('%o', fileperms($fn)), -4);
$fti = filemtime($fn);
$obj['filemtime'] = date('Y-m-d H:i:s', $fti);
if(stripos($obj['type'], 'image') !== false && $obj['filesize'] <= $cfg->thumbnail_max_size)
{
try
{
$is = getimagesize($fn);
if($is)
{
$obj['image_width'] = $is[0];
$obj['image_height'] = $is[1];
if(stripos($is['mime'], 'image')===0)
{
$obj['type'] = $is['mime'];
}
}
else
{
$obj['image_width'] = 0;
$obj['image_height'] = 0;
}
}
catch(Exception $e)
{
$obj['image_width'] = 0;
$obj['image_height'] = 0;
}
}
else
{
$obj['image_width'] = 0;
$obj['image_height'] = 0;
}
$arrfile[] = $obj;
}
}
}
}
$sortby = kh_filter_input(INPUT_GET, 'sortby', FILTER_SANITIZE_STRING);
if(!in_array($sortby, array('name', 'filesize', 'type', 'permission', 'filemtime')))
$sortby = '';
if($sortby == '')
$sortby = 'type';
$sortorder = kh_filter_input(INPUT_GET, 'sortorder', FILTER_SANITIZE_STRING);
if(!in_array($sortorder, array('asc', 'desc')))
$sortorder = '';
if($sortorder == '')
$sortorder = 'asc';
$_order = array();
foreach ($arrdir as &$row){
$_order[] = &$row['name'];
}
array_multisort($_order, SORT_ASC, SORT_STRING, $arrdir);
$_order = array();
$_order2 = array();
foreach ($arrfile as &$row){
$_order[] = &$row[$sortby];
$_order2[] = &$row['name'];
}
array_multisort($_order, ($sortorder=='desc')?SORT_DESC:SORT_ASC, $_order2, SORT_ASC, SORT_STRING, $arrfile);
if(count($arrfile))
{
foreach($arrfile as $key=>$val)
{
if(stripos($val['type'], 'image/') === 0)
{
$arrfile2[] = $val;
}
}
}
if(basename($_SERVER['PHP_SELF']) == basename(__FILE__))
{
header("Content-Type:text/plain; charset=utf-8");
}
echo json_encode($arrfile2);
?>