getCosConfig($site_id, $app_module); $config = $config_result["data"]; if ($config["is_use"] != 1) { $config_result = $config_model->getCosConfig(1); $config = $config_result["data"]; } if ($config["is_use"] == 1) { $cosinfo = $config['value']; $cosClient = new Client([ 'region' => $cosinfo['region'], 'schema' => 'https', //协议头部,默认为http 'credentials' => [ 'secretId' => $cosinfo['secretId'], 'secretKey' => $cosinfo['secretKey'] ] ]); ### 上传文件流 ### try { $bucket = $cosinfo['bucket']; //存储桶名称 格式:BucketName-APPID $file = fopen($file_path, 'rb'); if ($file) { $cosClient->Upload( $bucket = $bucket, $key = $key, $body = $file ); //返回图片的完整URL $domain = $cosinfo["domain"];//自定义域名 $data = array( "type" => 'cos', "path" => $domain . '/' . $key, "url" => $domain . '/' . $key, "domain" => $domain, "bucket" => $bucket ); return $this->success($data); } else { abort(404, '文件不存在'); } } catch (\Exception $e) { return $this->error($e->getMessage()); } } } }