-
Notifications
You must be signed in to change notification settings - Fork 296
Expand file tree
/
Copy pathconfig.php
More file actions
46 lines (37 loc) · 1011 Bytes
/
config.php
File metadata and controls
46 lines (37 loc) · 1011 Bytes
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
<?php
// 设置返回为 JSON
// http://127.0.0.1:9980/config.php
header('Content-Type: application/json; charset=utf-8');
// 当前目录
$dir = __DIR__;
// 当前脚本名
$self = basename(__FILE__);
// 扫描目录
$files = scandir($dir);
$sites = [];
foreach ($files as $file) {
// 只处理 php 文件
if (pathinfo($file, PATHINFO_EXTENSION) !== 'php') {
continue;
}
// 排除自身和 index.php
if ($file === $self || $file === 'index.php') {
continue;
}
// 文件名(不含 .php)
$filename = pathinfo($file, PATHINFO_FILENAME);
$sites[] = [
"key" => "php_" . $filename,
"name" => $filename . "(PHP)",
"type" => 4,
"api" => "http://127.0.0.1:9980/" . $filename . ".php",
"searchable" => 1,
"quickSearch" => 1,
"changeable" => 0
];
}
// 输出 JSON
echo json_encode(
["sites" => $sites],
JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT
);