php 网页ftp 代码一_PHP教程
$ftpserver="127.0.0.1";
$ftpport="21";
$ftpuser="anonymous";
$ftppassword="";
if($_POST)
{
$action=$_POST[action];
switch($action)
{
case "open":
case "change":
$ftpserver=$_POST[ftpserver];
$ftpport=$_POST[ftpport];
$ftpuser=$_POST[ftpuser];
$ftppassword=$_POST[ftppassword];
$ftp=@ftp_connect($ftpserver,$ftpport);
if(!$ftp){ echo "连接FTP服务器".$ftpserver."的端口".$ftpport."失败";exit;}
$rs=@ftp_login($ftp,$ftpuser,$ftppassword);
if(!$rs){ echo "用户名或密码错误,连接FTP服务器失败";exit;}
$curDir=$_POST[curDir];
if($curDir=="") $curDir="/";
if($curDir=="/")
{
$parentDir="/";
}else{
if(strrpos($curDir,"/")==0)
{
$parentDir="/";
}else{
$parentDir=substr($curDir,0,strrpos($curDir,"/"));
}
}
$arr=ftp_rawlist($ftp,$curDir);
if(count($arr)>1)
{
foreach($arr as $val)
{
if($curDir=="/")
{
$val="/" . trim(strrchr($val," "));
}else{
$val=$curDir . "/" . trim(strrchr($val," "));
}
$file_size=ftp_size($ftp,$val);
if($file_size==-1)
{//为目录
$dirlist[]=str_replace("\","/",$val);
}else{
$filelist[]=str_replace("\","/",$val);
}
}
}
break;
case "close":
break;
}
}
下面来看看WEB页面形式了.
?>