Home >php教程 >php手册 >php 网页ftp 代码一

php 网页ftp 代码一

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 11:22:14946browse

php 网页ftp 代码

 $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页面形式了.


?>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn