The example of this article describes the method of realizing autoindex effect of PHP simulation server. Share to everyone for your reference. The implementation methods are as follows:
The 1.PHP code is as follows:
Copy Code code as follows:
<?php
File Browsing Program
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);
?>
<title>pwd of <?php Echo $pwd?></title>
<body bgcolor= "White" >
<pre><a href= "? dir=<?php Echo dirname ($pwd)?>". /</a>
<?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 ());
? ><a href= "? dir=<?php Echo $file->getrealpath ()?>" ><?php echo $fileName? ></a><?php Echo Str_pad ($date, 60-strlen ($fileName), ', Str_pad_left ' ><?php echo str_pad ($fileSize, ",", Str_pad_left)? >
<?php}?></pre></body>
2. The operation effect is shown in the following illustration:
I hope this article will help you with your PHP program design.