首页  >  文章  >  php教程  >  php模拟服务器实现autoindex效果的方法

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

WBOY
WBOY原创
2016-06-06 20:06:571485浏览

这篇文章主要介绍了php模拟服务器实现autoindex效果的方法,实例分析了php操作URL及传递参数的技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了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() . 'http://www.jb51.net/';<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模拟服务器实现autoindex效果的方法

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

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

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn