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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

小囧   2021-03-21 我要评论
想了解php模拟服务器实现autoindex效果的方法的相关内容吗,小囧在本文为您仔细讲解php模拟服务器实现autoindex效果的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:php,模拟,服务器,autoindex效果,方法,下面大家一起来学习吧。

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

1.PHP代码如下:

复制代码 代码如下:
<?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);
?>
<html>
<head>
    <title>pwd of <?php echo $pwd ?></title>
</head>
<body bgcolor="white">
    <h1>pwd of <?php echo $pwd ?></h1><hr>
    <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,30,' ',STR_PAD_LEFT)?>
<?php }?></pre><hr>
</body>
</html>

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

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

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们