|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace addons\alioss;
|
|
|
|
|
|
+use app\common\model\Attachment;
|
|
|
use think\Addons;
|
|
|
|
|
|
/**
|
|
@@ -61,12 +62,12 @@ class Alioss extends Addons
|
|
|
/**
|
|
|
* 上传成功后
|
|
|
*/
|
|
|
- public function uploadAfter($attachment)
|
|
|
+ public function uploadAfter(Attachment $attachment)
|
|
|
{
|
|
|
$config = $this->getConfig();
|
|
|
- if ($config['uploadmode'] === 'server')
|
|
|
+ if ($config['uploadmode']/* === 'server'*/)
|
|
|
{
|
|
|
- $file = ROOT_PATH . 'public' . str_replace('/', DIRECTORY_SEPARATOR, $attachment->url);
|
|
|
+ $file = ROOT_PATH . 'public' . str_replace('/', DIRECTORY_SEPARATOR, parse_url($attachment->url,PHP_URL_PATH));
|
|
|
|
|
|
$name = basename($file);
|
|
|
$md5 = md5_file($file);
|
|
@@ -125,12 +126,15 @@ class Alioss extends Addons
|
|
|
$res = $client->request('POST', $uploadurl, $params);
|
|
|
$code = $res->getStatusCode();
|
|
|
//成功不做任何操作
|
|
|
+ if($config['uploadmode']=='client'){
|
|
|
+ if($attachment->id) {
|
|
|
+ $attachment->delete();
|
|
|
+ }
|
|
|
+ unlink($file);
|
|
|
+ }
|
|
|
}
|
|
|
catch (\GuzzleHttp\Exception\ClientException $e)
|
|
|
{
|
|
|
- $attachment->delete();
|
|
|
- //echo $e->getRequest()->getBody();
|
|
|
- unlink($file);
|
|
|
echo json_encode(['code' => 0, 'msg' => '无法上传到远程服务器,错误:' . $e->getMessage()]);
|
|
|
exit;
|
|
|
}
|