From 3576d40dc927b146def565d4f30e86d7d154bf8a Mon Sep 17 00:00:00 2001 From: WispX <1591788658@qq.com> Date: Sat, 29 Feb 2020 23:38:33 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=20BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/index/controller/Upload.php | 5 +++-- extend/strategy/driver/Remote.php | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/application/index/controller/Upload.php b/application/index/controller/Upload.php index 9b46535d..7f1d7dc4 100755 --- a/application/index/controller/Upload.php +++ b/application/index/controller/Upload.php @@ -91,8 +91,9 @@ class Upload extends Base $url = make_url($domain, $pathname); // 检测是否存在该图片,有则直接返回 - if ($oldImage = Images::where('md5', $md5)->find()) { - $url = make_url($domain, $oldImage->pathname); + if ($oldImage = Images::where('md5', $md5)->where('strategy', $currentStrategy)->find()) { + $pathname = $oldImage->pathname; + $url = make_url($domain, $pathname); goto exist; } diff --git a/extend/strategy/driver/Remote.php b/extend/strategy/driver/Remote.php index 1486bd42..2cc0bacb 100644 --- a/extend/strategy/driver/Remote.php +++ b/extend/strategy/driver/Remote.php @@ -23,7 +23,7 @@ class Remote implements Driver try { $this->ftp = new \FtpClient\FtpClient(); $this->ftp->connect($options['remote_host']); - $this->ftp->login($options['remote_name'], $options['remote_password']); + $this->ftp = $this->ftp->login($options['remote_name'], $options['remote_password']); } catch (FtpException $e) { $this->error = $e->getMessage(); } @@ -39,6 +39,8 @@ class Remote implements Driver */ public function create($pathname, $file) { + if (!$this->check()) return false; + try { $dirname = dirname($pathname); if (!$this->ftp->isDir($dirname)) { @@ -66,6 +68,8 @@ class Remote implements Driver */ public function delete($pathname) { + if (!$this->check()) return false; + try { if (!$this->ftp->remove($pathname, true)) { throw new FtpException('删除失败'); @@ -87,6 +91,8 @@ class Remote implements Driver */ public function deletes(array $list) { + if (!$this->check()) return false; + try { foreach ($list as $item) { if (!$this->ftp->remove($item, true)) { @@ -110,4 +116,14 @@ class Remote implements Driver { return 'Remote:' . $this->error; } + + private function check() + { + if (!extension_loaded('ftp')) { + $this->error = 'php_ftp 拓展未开启'; + return false; + } + + return true; + } }