LoginSignup
0
0

More than 5 years have passed since last update.

Indexes の代わりをする php スクリプト

Last updated at Posted at 2017-11-01

Indexes の代わりをする php スクリプト - hadacchi blogより転記

自分で管理しているサーバでは不要だが,会社のサーバなど管理者権限がなく,でもディレクトリ内のファイル一覧を見たいパスで,Indexesオプションの代わりをしてくれるphpスクリプトを作ってみた.
自分のブラウザ環境で,nginxのファイル一覧画面を参考に作ったものなので,多少のフォーマット変更は各人でヨロ.

index.php
<html>
<head><title>Index of <?php
if($_SERVER['SCRIPT_NAME']==$_SERVER['REQUEST_URI']) {
    if(dirname($_SERVER['REQUEST_URI'])=='/')  print '/';
    else print dirname($_SERVER['REQUEST_URI']).'/';
} else {
    print $_SERVER['REQUEST_URI'];
}
?></title></head>
<body bgcolor="white">
<h1>Index of /</h1><hr><pre>&lt;?php
foreach (scandir('.') as $val) {
    if ($val=='.') continue;
    elseif ($val=='..') print "&lt;a href=\"../\">../</a>\n";
    else {
        print "&lt;a href=\"$val\">$val</a>";
        for ($i=51-strlen($val);$i>0;--$i) print ' ';
        $st=stat($val);
        print date('d-M-Y H:i',$st[9]);
        for ($i=20-strlen("$st[7]");$i>0;--$i) print ' ';
        print $st[7]."\n";
    }
}
?>
</pre><hr></body>
</html>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0