我上传文件的ftp使用PHP。我已经创建了一个类来创建目录/上传文件等。我正在传递ftp登录详细信息,如下所示
$ftp_server="";
$ftp_user="";
$ftp_pass="";
//variable that connects to the FTP server
$connect = ftp_connect('',21,120);
//logins into FTP server account
ftp_login($connect, $ftp_user, $ftp_pass);
$uploader = new Uploader();
$pusher->Uploader("abc.php","abc_feeds.php",$connect);
这工作正常,但我想在我的Uploader类中添加ftp_connect函数,然后传递$This-
private function connect(){
if (!isset($this->ftp)){
$ftpConn= ftp_connect('',21,120) or die ("Cannot connect to host");
$this->ftpConnect = $ftpConn;
$ftpLogin=ftp_login($ftpConn, $this->ftp["user"], $this->ftp["pass"]) or die("Cannot login, wrong username or password");
ftp_pasv($this->ftp, true);
$this->status = 'Connected';
}
}
public function upload($filePath, $desPath) {
....
if (ftp_mkdir($this->ftpConnect, $this->ftpDrop)) {
echo "successfully created $dir\n";
} else {
echo "Error";
....
}
但问题是这一美元-
改变这个
if (!isset($this->ftpConnect)){
$ftpConn= ftp_connect('',21,120) or die ("Cannot connect to host");
$this->ftpConnect = $ftpConn;
$ftpLogin=ftp_login($ftpConn, $this->ftp["user"], $this->ftp["pass"]) or die("Cannot login, wrong username or password");
ftp_pasv($this->ftp, true);
$this->status = 'Connected';
}
到
if (!isset($this->ftp)){ // what is this? shouldn't it be if(!$this->ftpConnect)
$this->ftpConnect = ftp_connect('',21,120) or die ("Cannot connect to host");
$ftpLogin=ftp_login($this->ftpConnect, $this->ftp["user"], $this->ftp["pass"]) or die("Cannot login, wrong username or password"); //$ftpLogin is never used and can be removed because of the die( )
ftp_pasv($this->ftpConnect, true);
$this->status = 'Connected';
}
解释:
$this-
有几件事我放在评论里,我不确定,因为我没有完整的类来告诉他们默认应该是什么。