欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

基于阿里云sso实现简单下载站点

程序员文章站 2022-04-27 23:03:50
...
基于阿里云云存储的一个简单下载页,支持目录,操作方便

演示地址: DEMO

获取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;
        }
    }
}