<?php
function echoline($str)
{
echo $str."<br/>";
}
//=========================local file search recursive=========================================//
function searchfilebyname($filename,$dir)
{
$array_founds = array();
searchfile($filename,$dir,&$array_founds);
clearstatcache();// clear cached state
return $array_founds;
}
function searchfile($filename,$dir,&$array_founds)
{
if(is_file($dir))
{
if(strtolower(basename($dir)) == strtolower($filename))
{
array_push($array_founds,$dir);
}
}
else
{
$files = scandir($dir);
if($files)
{
while((list($k,$v) = each($files)))
{
if($v != "." && $v != "..") // exclude current director and parent directory
{
searchfile($filename,$dir."/".$v,&$array_founds);
}
}
}
}
}
//=========================local file search recursive=========================================//
//=========================ftp server file search recursive=========================================//
function ftp_searchfilebyname($ftp_connection,$filename,$dir)
{
$array_founds = array();
ftp_searchfile($ftp_connection,$filename,$dir,&$array_founds);
return $array_founds;
}
function ftp_searchfile($ftp_connection,$filename,$dir,&$array_founds)
{
if(stristr($dir,".") != null)
{
if(strtolower(basename($dir)) == strtolower($filename))
{
array_push($array_founds,$dir);
}
}
else
{
$files = ftp_nlist($ftp_connection,$dir);
if($files)
{
while((list($k,$v) = each($files)))
{
if($v != "." && $v != "..") // exclude current director and parent directory
{
$newdir;
if($dir == "/")
$newdir = "/$v";
else
$newdir = $dir."/".$v;
ftp_searchfile($ftp_connection,$filename,$newdir,&$array_founds);
}
}
}
}
}
// ==== test expample ===//
/*
include("dmphptool.php");
$fc = ftp_connect("192.168.1.101") or die("couldn't conenct");
if($fc)
{
$login = ftp_login($fc,"uname","pwd");
if($login)
{
$found = ftp_searchfilebyname($fc,"share.txt",ftp_pwd($fc));
if($found)
{
while(list($k,$v)=each($found))
{
ftp_nb_get($fc,"d:/".basename($v),$v,FTP_ASCII);
}
}
}
else
{
echo "not login";
}
ftp_close($fc);
}
*/
//=========================ftp server file search recursive=========================================//
?>
PHP 函数积累
最新推荐文章于 2024-07-29 22:50:36 发布