用php 的ftp函数上传文件到指定服务器

//获取ftp服务器名,账号,密码。并连接ftp服务器
  $max_size = 2000000;  //2M
  $filename = str_replace(” “,””,str_replace(‘.’,””,microtime()));
  $array = array(‘zip’,’rar’,’doc’,’ppt’,’swf’,’pps’,’avi’,’gif’,’jpg’);
  $array1 = array(‘jpg’,’gif’);
  $ftpserver = ‘192.168.0.172’;


  $ftpport   =21;
  $ftpuser = ‘resgameupload’;
  $ftppassword = ‘resgame#^)’;
  $ftp=@ftp_connect($ftpserver,$ftpport) or die(‘意外错误,请重新操作!’);
  $rs=@ftp_login($ftp,$ftpuser,$ftppassword) or die(‘意外错误,请重新操作!’);
  
  ///—————————————————————————————-
  $zip_file=$_FILES[‘ufile’][‘tmp_name’];
  $zip_file_size=$_FILES[‘ufile’][‘size’];
  $zip_file_type=$_FILES[‘ufile’][‘type’];
  $zip_file_name = $_FILES[‘ufile’][‘name’];
  $str = strtolower(substr($zip_file_name,strrpos($zip_file_name,’.’,0)+1,strlen($zip_file_name)));
  if($zip_file != “” ) {
    if($zip_file_size > $max_size ) {
       echo   “<script>alert(‘上传图片太大,请处理后重新上传.’)</script>”;
       echo “<script>location.href=’upload.php'</script>”;
       die();
    }
          if(!in_array($str,$array)) {
      echo   “<script>alert(‘格式不正确,请上传zip或rar格式文件.’)</script>”;
      echo “<script>location.href=’upload.php'</script>”;
      die();   
    } else  {
         $localfile = $zip_file;
         $remotefile = ‘./TecRes/’.$filename.”.”.$str;
      $file_name_zip = $filename.”.”.$str;
      //开始上传图片(FTP)
      $ftpzip=@ftp_put($ftp,$remotefile,$localfile,FTP_BINARY) or die (‘意外错误,请重新操作!’) ;
    }
  }
         ////——————————————————————————————–

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注