Home > php教程 > php手册 > php模拟服务器实现autoindex效果的方法,phpautoindex

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

WBOY
Release: 2016-06-13 09:12:44
Original
1530 people have browsed it

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

本文实例讲述了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>
Copy after login



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

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

Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template