对于本地,我们可以利用windows自带的查找去进行查找,但是对于线上的话,如查找ftp空间里面文件,本程序是很有用的。

php文件查找器源码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>php版文件查找(file search)</title>
</head>
<body>
<form action="" method="post">
<p> 文件查找(注:区分大小写)</p>
<p>路径:<input type="text" name="path" /></p>
<p>查找:<input type="text" name="key" /></p>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/ai/1478">
<img src="https://img.php.cn/upload/ai_manual/000/000/000/175680175192363.png" alt="豆绘AI">
</a>
<div class="aritcle_card_info">
<a href="/ai/1478">豆绘AI</a>
<p>豆绘AI是国内领先的AI绘图与设计平台,支持照片、设计、绘画的一键生成。</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="豆绘AI">
<span>485</span>
</div>
</div>
<a href="/ai/1478" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="豆绘AI">
</a>
</div>
<p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p>
<p><input type="submit" name="sub" value=" 开 始 " /></p>
</form>
</body>
</html>
<?php
/*
* 注:区分大小写
* by: http://www.daixiaorui.com
*/
if(!empty($_POST['path'])&&!empty($_POST['key'])){
echo "在路径 ".$_POST['path']."/ 中查找 ".$_POST['key']." 的结果为:<hr/>";
$file_num = $dir_num = 0;
$r_file_num = $r_dir_num= 0;
$findFile = $_POST['key'];
function delDirAndFile( $dirName ){
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'])){
echo " <span><b> $dirName/$item </b></span><br />\n";
$GLOBALS['r_file_num']++;
}
}
}
}
closedir( $handle );
$GLOBALS['dir_num']++;
if(strstr($dirName,$GLOBALS['findFile'])){
$loop = explode($GLOBALS['findFile'],$dirName);
$countArr = count($loop)-1;
if(empty($loop[$countArr])){
echo " <span style='color:#297C79;'><b> $dirName </b></span><br />\n";
$GLOBALS['r_dir_num']++;
}
}
}else{
die("没有此路径!");
}
}
delDirAndFile($_POST['path']);
echo "<hr/>本次共搜索到".$file_num."个文件,文件夹".$dir_num."个<br/>";
echo "<hr/>符合结果的共".$r_file_num."个文件,文件夹".$r_dir_num."个<br/>";
}
?>以上就是php文件查找器程序,可以搜索本地文件,便于操作,希望对大家的学习有所帮助。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号