accessKey = $accessKey; $this->secretKey = $secretKey; $this->endpoint = $endpoint; $this->bucketName = $bucketName; $this->ks3Client = new \Ks3Client($this->accessKey, $this->secretKey, $this->endpoint); } /* * @Title: 金山云上传 * @Description: TODO * $file:上传的文件 * $fileName:文件名 * $folder:文件目录 */ public function uploadFile($file, $fileName, $folder) { set_time_limit(0); $ks3FilePath = $folder. '/' . $fileName; $content = fopen($file->getPathname(), "r"); $args = [ "Bucket" => $this->bucketName, "Key" => $ks3FilePath, "Content" => [ "content" => $content, "seek_position" => 0, ], "ACL" => "public-read", "ObjectMeta" => [ "Content-Type" => "image/jpeg", "Content-Length" => $file->getSize(), ], ]; $ks3Result = $this->ks3Client->putObjectByFile($args); if (isset($ks3Result['ETag'])) { $ks3FullUrl = "http://$this->bucketName.$this->endpoint/$ks3FilePath"; return json(['code' => 0, 'data' => [ 'url' => $ks3FullUrl, 'name' => $fileName ], 'url' => $ks3FullUrl, 'msg' => '上传成功']); } else { return json(['code' => -1, 'data' => [], 'msg' => '上传失败']); } } }