Apache的目录列表为JSON [英] Apache directory listing as json

查看:238
本文介绍了Apache的目录列表为JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在阿帕奇返回JSON而不是HTML目录列表?

Is it possible to have the directory listing in apache return json instead of html?

我与Apache完全没有经验,但我已经为浏览和IndexOptions的mod_autoindex文档。好像没有内置的方法来配置输出。

I'm completely unexperienced with Apache, but I've browsed the documentation for IndexOptions and mod_autoindex. It seems like there's no built in way to configure the output.

推荐答案

我看了看在Apache源代码code中的code在模块/发电机/ mod_autoindex.c 和HTML代是静态的。您的可能的改写这个输出JSON,只需搜索所有的 ap_rputs ap_rvputs 功能电话和更换相应的JSON的HTML。这似乎是一个大量的工作,虽然。

I looked at the code in apache source code in modules/generators/mod_autoindex.c and the HTML generation is static. You could rewrite this to output JSON, simply search for all the ap_rputs and ap_rvputs function calls and replace the HTML with the appropriate JSON. That's seems like a lot of work though.

我想我会做到这一点,而不是...

I think I would do this instead...

在这个网站的Apache配置,更改为...

In the Apache configuration for this site, change to...

DirectoryIndex ls_json.php index.php index.html

,然后将 ls_json.php 脚本到您想要一个JSON EN codeD房源的任何目录:

And then place ls_json.php script into the any directory for which you want a JSON encoded listing:

// grab the files
$files = scandir(dirname(__FILE__));

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

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

这篇关于Apache的目录列表为JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆