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

前端 未结 4 2036
醉梦人生
醉梦人生 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条回答
  •  梦毁少年i
    2021-01-04 18:39

    For show advanced list of files and directories with sort, date, size, icon type,..., Save bellow content code as route.php file, and then run this command:

    php -S localhost:8080 -t . route.php
    

    And then open http://localhost:8080/ in the browser.

    Code:

    $f,'date'=>filemtime($path.$f),'url'=>'index.php?dir='.rawurlencode(trim("$dir/$f",'/')));
        else$files[]=array('name'=>$f,'size'=>filesize($path.$f),'date'=>filemtime($path.$f),'url'=>trim("$dir/".rawurlencode($f),'/'));
    }
    closedir($h);
    $current_dir_name = basename($dir);
    $up_dir=dirname($dir);
    $up_url=($up_dir!=''&&$up_dir!='.')?'index.php?dir='.rawurlencode($up_dir):'index.php';
    // END PHP ?>
    
    
    
    
    <?=$current_dir_name==''?'Directory list':$current_dir_name?>
    
    
    
    
    
        

    Preview:

    gist

提交回复
热议问题