首页 >php教程 >PHP源码 >基于阿里云sso实现简单下载站点

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

PHP中文网
PHP中文网原创
2016-05-25 17:08:581396浏览

基于阿里云云存储的一个简单下载页,支持目录,操作方便 

演示地址: 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;
        }
    }
}
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn