File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ // 设置返回为 JSON
3+ // http://127.0.0.1:9980/config.php
4+ header ('Content-Type: application/json; charset=utf-8 ' );
5+
6+ // 当前目录
7+ $ dir = __DIR__ ;
8+
9+ // 当前脚本名
10+ $ self = basename (__FILE__ );
11+
12+ // 扫描目录
13+ $ files = scandir ($ dir );
14+
15+ $ sites = [];
16+
17+ foreach ($ files as $ file ) {
18+ // 只处理 php 文件
19+ if (pathinfo ($ file , PATHINFO_EXTENSION ) !== 'php ' ) {
20+ continue ;
21+ }
22+
23+ // 排除自身和 index.php
24+ if ($ file === $ self || $ file === 'index.php ' ) {
25+ continue ;
26+ }
27+
28+ // 文件名(不含 .php)
29+ $ filename = pathinfo ($ file , PATHINFO_FILENAME );
30+
31+ $ sites [] = [
32+ "key " => "php_ " . $ filename ,
33+ "name " => $ filename . "(PHP) " ,
34+ "type " => 4 ,
35+ "api " => "http://127.0.0.1:9980/ " . $ filename . ".php " ,
36+ "searchable " => 1 ,
37+ "quickSearch " => 1 ,
38+ "changeable " => 0
39+ ];
40+ }
41+
42+ // 输出 JSON
43+ echo json_encode (
44+ ["sites " => $ sites ],
45+ JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT
46+ );
You can’t perform that action at this time.
0 commit comments