PHP 遍历FTP下目录和文件生成数据库--可以做小规模的FTP搜索引擎
时间:2007-01-25 来源:otask
//ftp信息$ftp_server="xxxxxxxxxxx"; //FTP服务器的地址$username="xxx"; //要查询目录$userpassword="xxxxxx"; //相映的密码//数据库信息$localhost="localhost"; //一般是localhost$datauser="xxx"; //数据库用户名$datapassword="xxxxx"; //数据库用户密码$database="xxxxx"; //数据库名称 //数据表建立信息 realfly是表名// CREATE TABLE realfly (// name text NOT NULL,// id tinyint(4) unsigned NOT NULL auto_increment,// date date DEFAULT '0000-00-00' NOT NULL,// time time DEFAULT '00:00:00' NOT NULL,// content longtext NOT NULL,// KEY id (id)// ); ?> ####################################################程序: FTP搜索引擎递归函数文件 ##文件: class.php ##姓名: 网络骑士 ##所用技术: php&mysql ##版本: v1.0 ##联系: [email protected] #################################################### function happy($ftp_stream,$directory,$link) { if(
is_dir
($directory)) { //$today=(date("Y")."-".date("m")."-".date("d")); //$content=$directory; //$time=date("H:i:s"); //$query="INSERT INTO realfly VALUES (', ', '$today', '$time', '$content');"; //mysql_query($query,$link); //$color="FF3399"; //echo "".$directory."
"; $result=
ftp_nlist
($ftp_stream,$directory); for ($j=0;$jcount[/url]
($result);$j++){ happy($ftp_stream,$result[$j],$link); } } else { $basename=
basename
($directory); $file=
explode
(".",$basename); $id=$i++; $today=(
date
("Y")."-".
date
("m")."-".
date
("d")); $content=$directory; //$content4=$directory; $time=
date
("H:i:s"); $query="INSERT INTO realfly VALUES ('$file[0]', '$id', '$today', '$time', '$content');";
mysql_query
($query,$link);
echo
$directory."
"; } } ?> include ("./search_ini.php"); include ("./class.php");####################################################程序: FTP搜索引擎主文件 ##文件: search.php ##姓名: 网络骑士 ##所用技术: php&mysql ##版本: v1.0 ##联系: [email protected] #################################################### $ftp_stream=
ftp_connect
($ftp_server,21);$login=
ftp_login
($ftp_stream,"$username","$userpassword");if(!$login||!$ftp_stream){
echo
"cannot connect to $ftp_server";
echo
"try again"; }else {
echo
".$color." size=+3 >connect to $ftp_server
CONGRATULATIONS!
"; } $link=
mysql_pconnect
("$localhost","$datauser","$datapassword");
mysql_select_db
("$database",$link);$this=
ftp_pwd
($ftp_stream);$this=@
ftp_chdir
($ftp_stream,""); $result=
ftp_nlist
($ftp_stream,$this);for ($i=0;$icount[/url]
($result);$i++){if (
is_dir
($result[$i])) { happy($ftp_stream,$result[$i],$link); } else {
echo
$result[$i]."
"; $basename=
basename
($result[$i]); $file=
explode
(".",$basename); $id=$i; $today=(
date
("Y")."-".
date
("m")."-".
date
("d")); $content="$result[$i]"; $time=
date
("H:i:s"); $query="INSERT INTO realfly VALUES ( '$file[0]', '$id', '$today', '$time', '$content');";
mysql_query
($query,$link); }}?> 以上是后台的搜索处理程序,下面是用户查询处理程序 ########################################### #软件名: FTP搜索引擎显示页面 # #版本: v1.0 # #所用技术: php&mysql # #作者: 网络骑士 # #联系方式: [email protected] # ########################################### include ("./search_ini.php"); //connect to database $link=
mysql_pconnect
("$localhost","$datauser","$datapassword") or
die
("无法连接服务器,请稍后再试!"); //select database
mysql_select_db
("$database",$link); //make query $query="select name,content from realfly where name='$query1' ";
echo
"您所查询的字段: ";
echo
"$query1.
";$i=0;$result=
mysql_query
($query,$link);if($result){while(
list
($name,$content)=
mysql_fetch_row
($result)) {
echo
"您所能查询到的结果: "; $content3="ftp://xxxxxxxx"; //你的FTP站点名称 $content2=
stristr
($directory,"/var/ftp"); $content=$content3.$content2;
echo
"$content
"; $i++; } } if($i==0) { $color="FF3399";
echo
".$color." size=2>真是太神奇了,居然没有找到,呵呵~~,再试试!
";} else
echo
"恭喜,您要查找的东东找到了,赶快下载吧!.
"; ?>
is_dir
($directory)) { //$today=(date("Y")."-".date("m")."-".date("d")); //$content=$directory; //$time=date("H:i:s"); //$query="INSERT INTO realfly VALUES (', ', '$today', '$time', '$content');"; //mysql_query($query,$link); //$color="FF3399"; //echo "".$directory."
"; $result=
ftp_nlist
($ftp_stream,$directory); for ($j=0;$jcount[/url]
($result);$j++){ happy($ftp_stream,$result[$j],$link); } } else { $basename=
basename
($directory); $file=
explode
(".",$basename); $id=$i++; $today=(
date
("Y")."-".
date
("m")."-".
date
("d")); $content=$directory; //$content4=$directory; $time=
date
("H:i:s"); $query="INSERT INTO realfly VALUES ('$file[0]', '$id', '$today', '$time', '$content');";
mysql_query
($query,$link);
echo
$directory."
"; } } ?> include ("./search_ini.php"); include ("./class.php");####################################################程序: FTP搜索引擎主文件 ##文件: search.php ##姓名: 网络骑士 ##所用技术: php&mysql ##版本: v1.0 ##联系: [email protected] #################################################### $ftp_stream=
ftp_connect
($ftp_server,21);$login=
ftp_login
($ftp_stream,"$username","$userpassword");if(!$login||!$ftp_stream){
echo
"cannot connect to $ftp_server";
echo
"try again"; }else {
echo
".$color." size=+3 >connect to $ftp_server
CONGRATULATIONS!
"; } $link=
mysql_pconnect
("$localhost","$datauser","$datapassword");
mysql_select_db
("$database",$link);$this=
ftp_pwd
($ftp_stream);$this=@
ftp_chdir
($ftp_stream,""); $result=
ftp_nlist
($ftp_stream,$this);for ($i=0;$icount[/url]
($result);$i++){if (
is_dir
($result[$i])) { happy($ftp_stream,$result[$i],$link); } else {
echo
$result[$i]."
"; $basename=
basename
($result[$i]); $file=
explode
(".",$basename); $id=$i; $today=(
date
("Y")."-".
date
("m")."-".
date
("d")); $content="$result[$i]"; $time=
date
("H:i:s"); $query="INSERT INTO realfly VALUES ( '$file[0]', '$id', '$today', '$time', '$content');";
mysql_query
($query,$link); }}?> 以上是后台的搜索处理程序,下面是用户查询处理程序 ########################################### #软件名: FTP搜索引擎显示页面 # #版本: v1.0 # #所用技术: php&mysql # #作者: 网络骑士 # #联系方式: [email protected] # ########################################### include ("./search_ini.php"); //connect to database $link=
mysql_pconnect
("$localhost","$datauser","$datapassword") or
die
("无法连接服务器,请稍后再试!"); //select database
mysql_select_db
("$database",$link); //make query $query="select name,content from realfly where name='$query1' ";
echo
"您所查询的字段: ";
echo
"$query1.
";$i=0;$result=
mysql_query
($query,$link);if($result){while(
list
($name,$content)=
mysql_fetch_row
($result)) {
echo
"您所能查询到的结果: "; $content3="ftp://xxxxxxxx"; //你的FTP站点名称 $content2=
stristr
($directory,"/var/ftp"); $content=$content3.$content2;
echo
"$content
"; $i++; } } if($i==0) { $color="FF3399";
echo
".$color." size=2>真是太神奇了,居然没有找到,呵呵~~,再试试!
";} else
echo
"恭喜,您要查找的东东找到了,赶快下载吧!.
"; ?>
相关阅读 更多 +
排行榜 更多 +