Home > Backend Development > PHP Tutorial > Method for php simulation server to achieve autoindex effect_PHP tutorial

Method for php simulation server to achieve autoindex effect_PHP tutorial

WBOY
Release: 2016-07-13 10:04:11
Original
876 people have browsed it

How to achieve autoindex effect by php simulation server

This article mainly introduces the method of php simulation server to achieve autoindex effect, and analyzes the techniques of php operating URL and passing parameters with examples. It has certain reference value, friends in need can refer to it

The example in this article describes the method of php simulated server to achieve the autoindex effect. Share it with everyone for your reference. The specific implementation method is as follows:

1.PHP code is as follows:

The code is as follows:

//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);
?>


pwd of <?php echo $pwd ?>


pwd of



<a href="?dir=<?php echo dirname($pwd)?>">../</a><br>
<?php <br />
foreach ($it as $file){ <br />
if($file->isDir()) {<br>
$fileSize = '_';<br>
$fileName = $file->getFilename() . '/';<br>
} elseif($file->isFile()) {<br>
$fileSize = $file->getSize();<br>
$fileName = $file->getFilename();<br>
}<br>
$date = date('Y-m-d H:i',$file->getCTime());<br>
?><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,30,' ',STR_PAD_LEFT)?><br>
<?php }?>



2. The operation effect is shown in the figure below:

php模拟服务器实现autoindex效果的方法   帮客之家

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/966369.htmlTechArticleHow to achieve the autoindex effect on the php simulation server. This article mainly introduces the method and examples of how to achieve the autoindex effect on the php simulation server. Analyzed the techniques of php operating URL and passing parameters, with...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template