欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-06-13 22:31:59
...
本文实例讲述了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



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



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

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

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

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