《PHP應用:php模擬服務器實現(xiàn)autoindex效果的方法》要點:
本文介紹了PHP應用:php模擬服務器實現(xiàn)autoindex效果的方法,希望對您有用。如果有疑問,可以聯(lián)系我們。
本文實例講述了php模擬服務器實現(xiàn)autoindex效果的辦法.分享給大家供大家參考.具體實現(xiàn)辦法如下:PHP學習
1.PHP代碼如下:
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學習
PHP學習
PHP學習
希望本文所述對大家的php程序設計有所贊助.PHP學習
歡迎參與《PHP應用:php模擬服務器實現(xiàn)autoindex效果的方法》討論,分享您的想法,維易PHP學院為您提供專業(yè)教程。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/11835.html