OSS数据同步指定二级目录下的文件
/** * OSS数据同步 * @return array * @throws OssException */ public function ossres() { $ossClient = new OssClient($this->accessKeyId, $this->accessKeySecret, $this->endpoint, true); $nextMarker = ''; while (true) { try { $prefix = 'hbbf-img/'; $options = array( 'delimiter' => '', 'marker' => $nextMarker, 'max-keys' => '1000', 'prefix' => $prefix, ); $listObjectInfo = $ossClient->listObjects($this->bucket, $options); } catch (OssException $e) { printf(__FUNCTION__ . ": FAILED\n"); printf($e->getMessage() . "\n"); return; } // 得到nextMarker,从上一次listObjects读到的最后一个文件的下一个文件开始继续获取文件列表。 $nextMarker = $listObjectInfo->getNextMarker(); $listObject = $listObjectInfo->getObjectList(); $listPrefix = $listObjectInfo->getPrefixList(); $imgres = []; if (!empty($listObject)) { foreach ($listObject as $objectInfo) { $imgr['url'] = 'https://hbsjsdoss.oss-cn-zhangjiakou.aliyuncs.com/'.$objectInfo->getKey(); $imgr['uid'] =2; $imgr['attr'] = 'img'; $imgr['uiid'] = '32'; $imgres[] = $imgr; } } dump($imgres);die; } }
[声明]原创不易,请转发者备注下文章来源(hbsjsd.cn)【速建时代】。