Home >Backend Development >PHP Tutorial >php web page ftp code 1_PHP tutorial
php web page ftp code
$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 "Connect to FTP server".$ftpserver."Port".$ ftpport."Failed";exit;}
$rs=@ftp_login($ftp,$ftpuser,$ftppassword);
if(!$rs){ echo "Incorrect username or password, failed to connect to FTP server ";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," ")); val," "));
}
🎜> $dirlist[]=str_replace("","/",$val);
$filelist[]=str_replace("","/",$val);
}
}
}
break;
case "close":
break;
}
}
Let’s take a look at the WEB page format.
?>
http://www.bkjia.com/PHPjc/445065.html
www.bkjia.com
http: //www.bkjia.com/PHPjc/445065.html