不说废话,直接代码
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>dir scan </title>
</head>
<body>
<form method="post">
目录遍历:<input type="text" name="dir">
<input type="submit" value="查询">
<?php
$dir=@$_POST['dir'];
echo $dir."<hr/>";
if(is_dir($dir)){
$opdir=opendir($dir);
while(($file=readdir($opdir))!==false){
$filename=$dir.'//'.$file;
if(is_dir($filename)&&$filename!='.'&&$filename!='..'){
echo "目录:".$filename."<br/>";
}else if($filename!='.'&&$filename!='..'){
echo "文件:".$filename."<br/>";
}
}
closedir($opdir);
}else if(is_file($dir)){
$myfile=fopen($dir, "r") or die("Unable to open file!");
while(!feof($myfile)){
echo fgets($myfile)."<br/>";
}
fclose($myfile);
}else{
echo "no dir ";
}
?>
</form>
</body>
</html>
读取文件
网友评论