递归调用delete_dir()
if( ! @delete_file($item)) {
$this->delete_dir($item);
}
}
}
//删除文件夹(空文件夹)
$result = @ftp_rmdir($this->conn_id, $path);
if($result === FALSE) {
if($this->debug === TRUE) {
$this->_error("ftp_unable_to_delete_dir:dir[".$path."]");
}
return FALSE;
}
return TRUE;
}
/**
* 修改文件权限
*
* @access public
* @param string 目录标识(ftp)
* @return boolean
*/
public function chmod($path, $perm) {
if( ! $this->_isconn()) {
return FALSE;
}
//只有在PHP5中才定义了修改权限的函数(ftp)
if( ! function_exists(''ftp_chmod'')) {
if($this->debug === TRUE) {
$this->_error("ftp_unable_to_chmod(function)");
}
return FALSE;
}
$result = @ftp_chmod($this->conn_id, $perm, $path);
if($result === FALSE) {
if($this->debug === TRUE) {
$this->_error("ftp_unable_to_chmod:path[".$path."]-chmod[".$perm."]");
}
return FALSE;
}
return TRUE;
}
/**
* 获取目录文件列表
*
* @access public
* @param string 目录标识(ftp)
* @return array
*/
public function filelist($path = ''.'') {
if( ! $this->_isconn()) {
return FALSE;
}
return ftp_nlist($this->conn_id, $path);
}
/**
* 关闭FTP
*
* @access public
* @return boolean
*/
public function close() {
if( ! $this->_isconn()) {
return FALSE;
}
return @ftp_close($this->conn_id);
}
/**
* FTP成员变量初始化
*
* @access private
* @param array 配置数组
* @return void
*/
private function _init($config = array()) {
foreach($config as $key => $val) {
if(isset($this->$key)) {
$this->$key = $val;
}
}
//特殊字符过滤
$this->hostname = preg_replace(''|.+?://|'','''',$this->hostname);
}
/**
* FTP登陆
*
* @access private
* @return boolean
*/
private function _login() {
return @ftp_login($this->conn_id, $this->username, $this->password);
}
/**
* 判断con_id
*
* @access private
* @return boolean
*/
private function _isconn() {
if( ! is_resource($this->conn_id)) {
if($this->debug === TRUE) {
$this->_error("ftp_no_connection");
}
return FALSE;
}
return TRUE;
}
/**
* 从文件名中获取后缀扩展
*
* @access private
* @param string 目录标识
* @return string
*/
private function _getext($filename) {
if(FALSE === strpos($filename, ''.'')) {
return ''txt'';
}
$extarr = explode(''.'', $filename);
return end($extarr);
}
/**
* 从后缀扩展定义FTP传输模式 ascii 或 binary
*
* @access private
* @param string 后缀扩展
* @return string
*/
private function _settype($ext) {
$text_type = array (
''txt'',
''text'',
''php'',
''phps'',
''php4'',
''js'',
''css'',
''htm'',
''html'',
''phtml'',
''shtml'',
''log'',
''xml''
);
return (in_array($ext, $text_type)) ? ''ascii'' : ''binary'';
}
/**
* 错误日志记录
*
* @access prvate
* @return boolean
*/
private function _error($msg) {
return @file_put_contents(''ftp_err.log'', "date[".date("Y-m-d H:i:s")."]-hos