This article describes how to implement autoindex on a php simulated server. The example analyzes php URL operations and passing parameters, which has some reference value, for more information about how to use php to simulate a server to achieve autoindex, see the example in this article. Share it with you for your reference. The specific implementation method is as follows:
1. the PHP code is as follows:
The code is as follows:
<? Php
// File Browser
Error_reporting (0 );
$ Pwd = empty ($ _ GET ['dir'])? './': $ _ GET ['dir'];
$ Pwd = realpath ($ pwd );
If (is_file ($ pwd )){
Highlight_file ($ pwd );
Exit;
} Else
$ It = new FilesystemIterator ($ pwd );
?>
Pwd of <? Php echo $ pwd?>
Pwd of <? Php echo $ pwd?>
">../
<?php
foreach ($it as $file){
if($file->isDir()) {
$fileSize = '_';
$fileName = $file->getFilename() . '/';
} elseif($file->isFile()) {
$fileSize = $file->getSize();
$fileName = $file->getFilename();
}
$date = date('Y-m-d H:i',$file->getCTime());
?>getRealPath()?>"><?php echo $fileName ?><?php echo str_pad($date, 60-strlen($fileName),' ',STR_PAD_LEFT)?><?php echo str_pad($fileSize,30,' ',STR_PAD_LEFT)?>
<?php }?>
2. shows the running effect:
I hope this article will help you with php programming.