美文网首页
一个简单的php搜索文档

一个简单的php搜索文档

作者: 因思道客 | 来源:发表于2018-11-13 11:30 被阅读0次

一个简单的检索本地文件,可以拿来作为发布标准规范,用来查询还是很方便的。

<html>

<head>

  <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

  <link href="css/wap.css" rel="stylesheet" type="text/css" />

  <title>标准规范查询</title>

</head>

<body>

  <form action="" method="post">

  <div id="create_form" align='center'>

  <p> (注:区分大小写不支持多关键词,建议只输入标准序号或名称)</p>

  <p>请输入关键字:<input type="text" name="key" /><input type="submit" name="sub" value=" 查 询 " /></p>

  </div>

  </form>

<?php

if(!empty($_POST['key'])){

$file_num = $dir_num = 0;

$r_file_num = $r_dir_num= 0;

$findFile = $_POST['key'];

echo "<table>";

echo "<tr class=\"tt\"><td>序号</td><td>文件名</td><td>大小</td></tr>";

function delDirAndFile( $dirName ){

static $num =0;

  if ( $handle = @opendir( "$dirName" ) ) {

  while ( false !== ( $item = readdir( $handle ) ) ) { 

    if ( $item != "." && $item != ".." ) { 

    if ( is_dir( "$dirName/$item" ) ) { 

      delDirAndFile( "$dirName/$item" );

    } else { 

      $GLOBALS['file_num']++;

      if(strstr($item,$GLOBALS['findFile'])){

  $num++;

  $subfile =str_replace('D:\wwwroot\stds','http://192.168.0.1/stds', $dirName );

  $Size= filesize("$dirName/$item");

  $Size= number_format($Size/1000000, 2);

  //$subfile =str_replace('.','-',$subfile);

      echo " <tr><td align='center'>$num</td><td><a target=\"_blank\" href=\"$subfile/$item \">$item</a></td><td>$Size MB</td></tr>\n";

      $GLOBALS['r_file_num']++;

      }

    } 

    }

  }

  closedir( $handle ); 

  }

}

delDirAndFile('D:\\wwwroot\\stds');

echo "</table><div align='center'>从 $file_num 个文件中,查询到".$r_file_num."个文件,下载请直接右键另存。</div>";

}

?>

</body>

</html>

相关文章

网友评论

      本文标题:一个简单的php搜索文档

      本文链接:https://www.haomeiwen.com/subject/lsuaxqtx.html