[PHP]listing.php
下図の赤線のhtmlへのリンクを書き出すphp。
index.php
<ul> <?php function getDirList($trgDir){ $a = array(); if ($dir = opendir($trgDir)) { while (($file = readdir($dir)) !== false) { if ($file != "." && $file != "..") { if(is_dir($trgDir.'/'.$file)){ array_push($a, $file); } } } closedir($dir); return $a; } } function getFileList($dir,$ext){ $res_dir = opendir($dir); $list=array(); while( $file_name = readdir( $res_dir ) ){ if($ext){ $n=explode('.' , $file_name); if($n[1]==$ext)array_push($list,$file_name); }else{ array_push($list,$file_name); } } closedir( $res_dir ); return $list; } function sortByTimestamp($list){ usort($list,'sortByTimestampCmp'); return $list; } function sortByTimestampCmp($a,$b){ $at=filemtime($a); $bt=filemtime($b); if($at==$bt)return 0; return ($at<$bt)?-1:1; } function echoList($list,$format){ foreach($list as $dir){ $n=getFileList($dir,"html"); foreach($n as $f){ $m=$dir . '/' . $f; if($format){ echo preg_replace('/%@/',$m,$format); }else{ echo $m; } } } } $dir_list=getDirList("./"); $dir_list=sortByTimestamp($dir_list); $dir_list=array_reverse($dir_list); echoList($dir_list,'<li><a href="%@" target="_self">%@</a></li>'); ?> </ul>