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

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

PHP中文网
PHP中文网Original
2016-05-25 17:08:581400browse

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

演示地址: 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;
        }
    }
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:基于CI的头像上传Next article:php服务器限速代码