gpt4 book ai didi

Apache 目录列表为 json

转载 作者:行者123 更新时间:2023-12-04 14:28:44 25 4
gpt4 key购买 nike

是否可以让 apache 中的目录列表返回 json 而不是 html?

我对 Apache 完全没有经验,但我已经浏览了 IndexOptions 和 mod_autoindex 的文档。似乎没有内置的方式来配置输出。

最佳答案

我查看了 modules/generators/mod_autoindex.c 中 apache 源代码中的代码并且 HTML 生成是静态的。您可以将其重写为输出 JSON,只需搜索所有 ap_rputsap_rvputs函数调用并用适当的 JSON 替换 HTML。不过,这似乎是很多工作。

我想我会这样做......

在此站点的 Apache 配置中,更改为...

DirectoryIndex ls_json.php index.php index.html

然后放置 ls_json.php脚本到您想要 JSON 编码列表的任何目录中:
// grab the files
$files = scandir(dirname(__FILE__));

// remove "." and ".." (and anything else you might not want)
$output = [];
foreach ($files as $file)
if (!in_array($file, [".", ".."]))
$output[] = $file;

// out we go
header("Content-type: application/json");
echo json_encode($output);

关于Apache 目录列表为 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20448339/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com