是否有可能在Apache的目录列表返回JSON而不是HTML?Apache目录列表为json
我对Apache完全没有经验,但我浏览了IndexOptions和mod_autoindex的文档。似乎没有内置的方式来配置输出。
是否有可能在Apache的目录列表返回JSON而不是HTML?Apache目录列表为json
我对Apache完全没有经验,但我浏览了IndexOptions和mod_autoindex的文档。似乎没有内置的方式来配置输出。
我查看了modules/generators/mod_autoindex.c
中apache源代码,并且HTML生成是静态的。你可能重写此输出JSON,只需搜索所有ap_rputs
和ap_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);
这几乎是我最终使用的。太棒了。 – Rjoss
你可以按如下方式使用mod_dir - 创建一个php脚本并列出你想要的目录(根据需要设置内容类型)。
我写和Apache模块,做到了这一点
https://github.com/teknopaul/mod_upload
项目有两个模块mod_jsonindex.so是一个你想
FYI Nginx已经JSON索引建于
你看着[mod_dir(HTTP://httpd.apache。组织/文档/ 2.2/MOD/mod_dir.html)? –
好的结果 - 这正是我需要使用的。 – Rjoss