柳暗花明笔记

    php ftp 简单上传例子2

    所属分类:[ php&web ] 猫哲学家 发表于:2012-08-10 22:19 浏览:451

    class php_ftp{                  private $ftpUrl = '';         private $ftpUser = '';         private $ftpPass = '';         private $ftpDir = '';                  function __construct($ftpUrl='', $ftpUser='', $ftpPass='', $ftpDir='') {             if($ftpUrl){                 $this->ftpUrl = $ftpUrl;             }             if($ftpUser){                 $this->ftpUser = $ftpUser;             }             if($ftpPass){                 $this->ftpPass = $ftpPass;             }             if($ftpDir){                 $this->ftpDir = $ftpDir;             }         }                  function upload($uploadArray){             if(empty($uploadArray)){                 return false;             }             foreach($uploadArray as $v){                 $result = $this->uploadone($v);                 if(true === $result){                     //success                 }else{                     return $result;                 }             }         }                  //return true = Successfully  false = Failure 2 = Read Failure 3 = Login Failure         function uploadone($file){             if($file){                         $path = $this->ftpDir;                 $exten = substr($file,-3); // Not used, determining the extension of the file                 $saveas = $path . basename($file);                          // Read the remote file                 if($fp = fopen($file, "rb")){                     // set up basic connection                     $conn_id = ftp_connect($this->ftpUrl);                     // login with username and password                     $login_result = ftp_login($conn_id, $this->ftpUser, $this->ftpPass);                     if(!$login_result){                         return '3';                     }                     // try to upload $file                     if (ftp_fput($conn_id, $saveas, $fp, FTP_BINARY)) {                         return true;                     }else {                         return false;                     }                     // close the connection and the file handler                     ftp_close($conn_id);                     fclose($fp);                 }else{                     // Could not read the file, may be protected by remote server                     return '2';                 }             }                  }              }
    标签: php 
    上一编文章 php ftp 上传例子 下一编文章 linux nscd进程管理DNS缓存,清除缓存,加快上网速度
    最近文章
    发表评论