isdir($v))
$result.= 文件:.pathinfo(iconv('gbk', 'utf-8', $v),pathinfo_basename).
;
else
$result.= 目录:.pathinfo(iconv('gbk', 'utf-8', $v),pathinfo_basename).
;
}
$this->assign('result',$result);
$this->display();
}
}模板调用{$result}即可。host=$host;
$this->port=$port;
$this->user=$user;
$this->pwd=$pwd;
$this->mode=$mode;
$this->timeout=$timeout;
$this->ssl=$ssl;
if($ssl){
$this->conn=ftp_ssl_connect($this->host,$this->port,$this->timeout) or die(ftp连接失败!);
}else{
$this->conn=ftp_connect($this->host,$this->port,$this->timeout) or die(ftp连接失败!);
}
ftp_login($this->conn, $user, $pwd) or die(无法打开ftp连接);
}
/**
* 返回给定目录的文件列表
* @param string $dirname 目录地址
* @return array 文件列表数据
*/
public function nlist($dirname) {
if ($list = @ftp_nlist($this->conn, $dirname)) {
return $list;
}
}
/**
* 返回上级目录
* @return boolean
*/
function back_dir()
{
return ftp_cdup($this->conn);
}
/**
* 取得指定目录下文件的详细列表信息
* @param $dirname 目录名称
* @return arrayobject
*/
function get_file_info($dirname)
{
$list = @ftp_rawlist($this->conn,$dirname);
if(!$list) return false;
$array = array();
foreach($list as $l)
{
$l = preg_replace(/^.*[ ]([^ ]+)$/, \\1, $l);
if($l == '.' || $l == '..') continue;
$array[] = $l;
}
return $array;
}
/**
* 创建文件夹
* @param string $dirname 目录名,
*/
public function mkdir($dirname) {
$dirname = $this->checkdir($dirname);
$nowdir = '/';
foreach ($dirname as $v) {
if ($v && !$this->cd($nowdir . $v)) {
if ($nowdir)
$this->cd($nowdir);
@ftp_mkdir($this->conn, $v);
}
if ($v)
$nowdir .= $v . '/';
}
return true;
}
/**
* 文件和目录重命名
* @param $old_name 原名称
* @param $new_name 新名称
* @return boolean
*/
function rename($old_name,$new_name)
{
return ftp_rename($this->conn,$old_name,$new_name);
}
/**
* 上传文件
* @param string $remote 远程存放地址
* @param string $local 本地存放地址
*/
public function put($remote, $local) {
$dirname = pathinfo($remote, pathinfo_dirname);
if (!$this->cd($dirname)) {
$this->mkdir($dirname);
}
if (@ftp_put($this->conn, $remote, $local, $this->mode)) {
return true;
}
}
/**
* 获取文件的最后修改时间
* @return string $time 返回时间
*/
public function lastupdatetime($file){
return ftp_mdtm($this->conn,$file);
}
/**
* 删除指定文件
* @param string $filename 文件名
*/
public function delete($filename) {
if (@ftp_delete($this->conn, $filename)) {
return true;
}
}
/**
* 在 ftp 服务器上改变当前目录
* @param string $dirname 修改服务器上当前目录
*/
public function cd($dirname) {
if (@ftp_chdir($this->conn, $dirname)) {
return true;
}
}
/**
* 在 ftp 服务器上返回当前目录
* @return string $dirname 返回当前目录名称
*/
public function getpwd() {
return ftp_pwd($this->conn);
}
/**
* 检测目录名
* @param string $url 目录
* @return 由 / 分开的返回数组
*/
private function checkdir($url) {
$url = str_replace('', '/', $url);
$urls = explode('/', $url);
return $urls;
}
/**
* 检测是否为目录
* @param string $dir 路径
* @return boolean true为目录false为文件
*/
public function isdir($dir) {
if ($this->cd($dir)){
return true;
}else{
return false;
}
}
/**
* 关闭ftp连接
*/
public function close() {
return @ftp_close($this->conn);
}
}
ad:真正免费,域名+虚机+企业邮箱=0元