PHP 函数积累

<?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=========================================//
	
?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值