Rjo*_*oss 6 apache directory-listing mod-autoindex
是否有可能让apache中的目录列表返回json而不是html?
我对Apache完全缺乏经验,但我浏览了IndexOptions和mod_autoindex的文档.似乎没有内置的方法来配置输出.
我查看了apache源代码中的代码,modules/generators/mod_autoindex.cHTML生成是静态的.您可以将其重写为输出JSON,只需搜索所有ap_rputs和ap_rvputs函数调用,并使用适当的JSON替换HTML.这似乎是很多工作.
我想我会这样做......
在此站点的Apache配置中,更改为...
DirectoryIndex ls_json.php index.php index.html
Run Code Online (Sandbox Code Playgroud)
然后将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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3139 次 |
| 最近记录: |