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)【速建時代】。