PHP用用FTP类上传文件视频等的简单实现方法类上传文件视频等的简单实现方法
文件文件1::ftp.php
<?php
/**
* 仿写CodeIgniter的FTP类
* FTP基本操作:
* 1) 登陆; connect
* 2) 当前目录文件列表; filelist
* 3) 目录改变; chgdir
* 4) 重命名/移动; rename
* 5) 创建文件夹; mkdir
* 6) 删除; delete_dir/delete_file
* 7) 上传; upload
* 8) 下载 download
*
* @author quanshuidingdang
*/
class Ftp {
private $hostname
= '';
private $username
= '';
private $password
= '';
private $port
= 21;
private $passive
= TRUE;
private $debug
= TRUE;
private $conn_id
= FALSE;
/**
* 构造函数
*
* @param array 配置数组 : $config = array('hostname'=>'','username'=>'','password'=>'','port'=>''...);
*/
public function __construct($config = array()) {
if(count($config) > 0) {
$this->_init($config);
}
}
/**
* FTP连接
*
* @access public
* @param array 配置数组
* @return boolean
*/
public function connect($config = array()) {
if(count($config) > 0) {
$this->_init($config);
}
//判断是否打开了ftp连接
if(FALSE === ($this->conn_id = @ftp_connect($this->hostname,$this->port))) {
if($this->debug === TRUE) {
$this->_error("ftp_unable_to_connect");
}
return FALSE;
}
//判断是否登录成功
if( ! $this->_login()) {
if($this->debug === TRUE) {
$this->_error("ftp_unable_to_login");
}