Home  >  Article  >  Backend Development  >  php模拟服务器实现autoindex效果的方法_PHP

php模拟服务器实现autoindex效果的方法_PHP

WBOY
WBOYOriginal
2016-05-31 13:13:26988browse

本文实例讲述了php模拟服务器实现autoindex效果的方法。分享给大家供大家参考。具体实现方法如下:

1.PHP代码如下:

代码如下:

//文件浏览程序
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


   

pwd of



   
<a href="?dir=<?php%20echo%20dirname(%24pwd)?>">../</a><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%20echo%20%24file->getRealPath()?>"></a><br>



2. 运行效果如下图所示:

希望本文所述对大家的php程序设计有所帮助。

Statement:
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