在官网提供的ftp上传类文件存在错误!
设定rootpath/**
* 检测上传根目录
* @param string $rootpath 根目录
* @return boolean true-检测通过,false-检测失败
*/
public function checkrootpath($rootpath){
/* 设置根目录 */
$this->rootpath = ftp_pwd($this->link);
if(!@ftp_chdir($this->link, $this->rootpath)){
$this->error = '上传根目录不存在!';
return false;
}
return true;
}重写save方法 /**
* 保存指定文件
* @param array $file 保存的文件信息
* @param boolean $replace 同名文件是否覆盖
* @return boolean 保存状态,true-成功,false-失败
*/
public function save($file, $replace=true) {
$filename = $this->rootpath . $file['savepath'] . $file['savename'];
/* 不覆盖同名文件 */
if (!$replace) {
ftp_chdir($this->link, $this->rootpath . $file['savepath']);
$ftpfilelist = ftp_nlist($this->link, .);
if(in_array($file['savename'], $ftpfilelist)) {
$this->error = '存在同名文件' . $file['savename'];
return false;
}
}
/* 移动文件 */
if (!ftp_put($this->link, $filename, $file['tmp_name'], ftp_binary)) {
$this->error = '文件上传保存错误!';
return false;
}
return true;
}
ad:真正免费,域名+虚机+企业邮箱=0元