- #获取object列表
- function list_object($obj,$dir='',$bucket=BUCKET){
- $options = array(
- 'delimiter' => '/',
- 'prefix' => $dir,
- 'max-keys' => 100,
- );
- $response = $obj->list_object($bucket,$options);
- return $response->body;
- }
- #处理返回内容
- // 处理目录
- if(isset($list_object['CommonPrefixes'])){
- foreach($list_object['CommonPrefixes'] as $s){
- $prefix = is_array($s)?$s['Prefix']:$s;
- $file['path'] = "http://".$_SERVER ['HTTP_HOST'].$_SERVER['PHP_SELF'].'?dir='.$prefix;
- $file['Prefix'] = $prefix;
- $dir_arr[] = $file;
- }
- }
- // 处理文件
- if(isset($list_object['Contents'])){
- foreach($list_object['Contents'] as $k=>$s){
- if ($k!="0"){
- $file['path'] = (get_sign_url($oss_sdk_service,$s['Key']));
- $file['Key'] = str_replace($list_object['Contents']['0']['Key'],"",$s['Key']);
- $file['Size'] = formatter_size($s['Size']);
- $file_arr[] = $file;
- }
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/290820135419.html
来源: http://www.codesnippet.cn/detail/290820135419.html