Home > php教程 > PHP源码 > body text

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

PHP中文网
Release: 2016-05-25 17:08:58
Original
1374 people have browsed it

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

演示地址: 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;
}
Copy after login



处理返回内容

// 处理目录
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;
        }
    }
}
Copy after login
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template