PHP实现类似ftp操作的文件管理类
2013-07-26 15:04
288 查看
PHP实现类似ftp操作的文件管理类,具体代码如下:
<?PHP
/**
* 仿写CodeIgniter的FTP类
* FTP基本操作:
* 1) 登陆; connect
* 2) 当前目录文件列表; filelist
* 3) 目录改变; chgdir
* 4) 重命名/移动; rename
* 5) 创建文件夹; mkdir
* 6) 删除; delete_dir/delete_file
* 7) 上传; upload
* 8) 下载 download
*
*
*/
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);
}
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");
}
return FALSE;
}
if($this->passive === TRUE) {
ftp_pasv($this->conn_id, TRUE);
}
return TRUE;
}
/**
* 目录改变
*
* @access public
* @param string 目录标识(ftp)
* @param boolean
* @return boolean
*/
public function chgdir($path = '', $supress_debug = FALSE) {
if($path == '' OR ! $this->_isconn()) {
return FALSE;
}
$result = @ftp_chdir($this->conn_id, $path);
if($result === FALSE) {
if($this->debug === TRUE AND $supress_debug == FALSE) {
$this->_error("ftp_unable_to_chgdir:dir[".$path."]");
}
return FALSE;
}
return TRUE;
}
/**
* 目录生成
*
* @access public
* @param string 目录标识(ftp)
* @param int 文件权限列表
* @return boolean
*/
public function mkdir($path = '', $permissions = NULL) {
if($path == '' OR ! $this->_isconn()) {
return FALSE;
}
$result = @ftp_mkdir($this->conn_id, $path);
if($result === FALSE) {
if($this->debug === TRUE) {
$this->_error("ftp_unable_to_mkdir:dir[".$path."]");
}
return FALSE;
} 转载请注明诚信在线娱乐http://www.shall-market.com
<?PHP
/**
* 仿写CodeIgniter的FTP类
* FTP基本操作:
* 1) 登陆; connect
* 2) 当前目录文件列表; filelist
* 3) 目录改变; chgdir
* 4) 重命名/移动; rename
* 5) 创建文件夹; mkdir
* 6) 删除; delete_dir/delete_file
* 7) 上传; upload
* 8) 下载 download
*
*
*/
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);
}
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");
}
return FALSE;
}
if($this->passive === TRUE) {
ftp_pasv($this->conn_id, TRUE);
}
return TRUE;
}
/**
* 目录改变
*
* @access public
* @param string 目录标识(ftp)
* @param boolean
* @return boolean
*/
public function chgdir($path = '', $supress_debug = FALSE) {
if($path == '' OR ! $this->_isconn()) {
return FALSE;
}
$result = @ftp_chdir($this->conn_id, $path);
if($result === FALSE) {
if($this->debug === TRUE AND $supress_debug == FALSE) {
$this->_error("ftp_unable_to_chgdir:dir[".$path."]");
}
return FALSE;
}
return TRUE;
}
/**
* 目录生成
*
* @access public
* @param string 目录标识(ftp)
* @param int 文件权限列表
* @return boolean
*/
public function mkdir($path = '', $permissions = NULL) {
if($path == '' OR ! $this->_isconn()) {
return FALSE;
}
$result = @ftp_mkdir($this->conn_id, $path);
if($result === FALSE) {
if($this->debug === TRUE) {
$this->_error("ftp_unable_to_mkdir:dir[".$path."]");
}
return FALSE;
} 转载请注明诚信在线娱乐http://www.shall-market.com
相关文章推荐
- php常用类之ftp文件操作
- java操作FTP,实现文件上传下载删除操作
- 在php中ftp上传文件到服务器的操作
- 发个 PHP 实现文件遍历操作的代码
- Microsoft .NET Framework 2.0对文件传输协议(FTP)操作(上传,下载,新建,删除,FTP间传送文件等)实现汇总1
- PHP的文件操作与算法实现的面试题示例
- FtpHelper实现ftp服务器文件读写操作(C#)
- php实现通过ftp上传文件
- Microsoft .NET Framework 2.0对文件传输协议(FTP)操作(上传,下载,新建,删除,FTP间传送文件等)实现汇总1
- Microsoft .NET Framework 2.0对文件传输协议(FTP)操作(上传,下载,新建,删除,FTP间传送文件等)实现汇总1
- Microsoft .NET Framework 2.0对文件传输协议(FTP)操作(上传,下载,新建,删除,FTP间传送文件等)实现汇总1
- PHP文件操作实现代码分享
- FTPClientHelper辅助类 实现文件上传,目录操作,下载等操作
- .Net 2.0对文件传输协议(FTP)操作(上传,下载,新建,删除,FTP间传送文件等)实现汇总
- PHP的文件操作与算法实现的面试题示例
- Microsoft .NET Framework 2.0对文件传输协议(FTP)操作(上传,下载,新建,删除,FTP间传送文件等)实现汇总1
- java操作ftp实现文件的上传下载(适用于图片文档服务器)
- python实现类似ftp传输文件的网络程序示例
- PHP实现适用于文件内容操作的分页类
- php实现通过ftp上传文件