PHP built in server, any way to configure it to show files of directory?

前端 未结 4 2040
醉梦人生
醉梦人生 2021-01-04 18:14

As yous may be aware, as of PHP 5.4 there is built in server available. However, if you browse to directory with no \"index\" file, instead if listing all available files/di

4条回答
  •  暖寄归人
    2021-01-04 18:30

    As mentioned by Colin in his comment, the integrated server is intended for debugging purposes only, therefore you should expect it to not have all the features you would expect of a full server.

    However, it's easy enough to build your own index.php to simulate the default Apache index:

    Index of ".$dir.":";
    $g = glob("*");
    usort($g,function($a,$b) {
        if(is_dir($a) == is_dir($b))
            return strnatcasecmp($a,$b);
        else
            return is_dir($a) ? -1 : 1;
    });
    echo implode("
    ",array_map(function($a) {return ''.$a.'';},$g));

提交回复
热议问题