OSS數(shù)據(jù)同步指定二級(jí)目錄下的文件
/** * OSS數(shù)據(jù)同步 * @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讀到的最后一個(gè)文件的下一個(gè)文件開(kāi)始繼續(xù)獲取文件列表。 $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; } }
[聲明]原創(chuàng)不易,請(qǐng)轉(zhuǎn)發(fā)者備注下文章來(lái)源(hbsjsd.cn)【速建時(shí)代】。