PHP Class BaiduBCS

Datei anzeigen Open project: zblogcn/zblogphp Class Usage Examples

Public Properties

Property Type Description
$ACL_ACTIONS
$ACL_EFFECTS
$ACL_TYPES SDK中开放此上五种acl_tpe

Protected Properties

Property Type Description
$use_ssl 是否使用ssl

Public Methods

Method Description
__construct ( string $ak = null, string $sk = null, string $hostname = null ) 构造函数
copy_object ( array $source, array $dest, array $opt = [] ) : BCS_ResponseCore 通过此方法以拷贝的方式创建object,object来源为$source
create_bucket ( string $bucket, string $acl = null, array $opt = [] ) : BCS_ResponseCore 创建 bucket
create_object ( string $bucket, string $object, string $file, array $opt = [] ) : BCS_ResponseCore 上传文件
create_object_by_content ( string $bucket, string $object, $content, array $opt = [] ) : BCS_ResponseCore 上传文件
create_object_superfile ( string $bucket, string $object, string $file, array $opt = [] ) : BCS_ResponseCore 通过superfile的方式上传文件
delete_bucket ( string $bucket, array $opt = [] ) : boolean | BCS_ResponseCore 删除bucket
delete_object ( string $bucket, string $object, array $opt = [] ) : BCS_ResponseCore 删除object
generate_delete_object_url ( string $bucket, string $object, $opt = [] ) 生成delete_object的url
generate_get_object_url ( string $bucket, string $object, $opt = [] ) 生成get_object的url
generate_head_object_url ( string $bucket, string $object, $opt = [] ) 生成head_object的url
generate_post_object_url ( string $bucket, string $object, $opt = [] ) 生成post_object的url
generate_put_object_url ( string $bucket, string $object, $opt = [] ) 生成put_object的url
getUse_ssl ( ) : the
get_bucket_acl ( string $bucket, array $opt = [] ) : BCS_ResponseCore 获取bucket的acl
get_filetree ( string $dir, $file_prefix = "/*" ) : array 获取传入目录的文件列表
get_object ( string $bucket, string $object, array $opt = [] ) : BCS_ResponseCore 下载object
get_object_acl ( string $bucket, string $object, array $opt = [] ) : BCS_ResponseCore 获取object的acl
get_object_info ( string $bucket, string $object, array $opt = [] ) : array 获取文件信息,发送的为HTTP HEAD请求,文件信息都在http response的header中,不会提取文件的内容
is_object_exist ( string $bucket, string $object, array $opt = [] ) : boolean 判断object是否存在
list_bucket ( array $opt = [] ) : BCS_ResponseCore 获取当前密钥对拥有者的bucket列表
list_object ( string $bucket, array $opt = [] ) : BCS_ResponseCore 获取bucket中object列表
list_object_by_dir ( string $bucket, $dir = '/', string $list_model = 2, array $opt = [] ) : BCS_ResponseCore 以目录形式获取bucket中object列表
log ( string $log, array $opt ) 内置的日志函数,可以根据用户传入的log函数,进行日志输出
setUse_ssl ( boolean $use_ssl )
set_bucket_acl ( string $bucket, string $acl, array $opt = [] ) : boolean | BCS_ResponseCore 设置bucket的acl,有三种模式, (1).设置详细json格式的acl; a. $acl 为json的array b. $acl 为json的string (2).通过acl_type字段进行设置 a. $acl 为BaiduBCS::$ACL_TYPES中的字段
set_object_acl ( string $bucket, string $object, string | array $acl, array $opt = [] ) : BCS_ResponseCore 设置object的acl,有三种模式, (1).设置详细json格式的acl; a. $acl 为json的array b. $acl 为json的string (2).通过acl_type字段进行设置 a. $acl 为BaiduBCS::$ACL_ACTIONS中的字段
set_object_meta ( string $bucket, string $object, $meta, array $opt = [] ) : BCS_ResponseCore 设置object的meta信息
trimUrl ( $url ) : string 将url中 '//' 替换为 '/'
upload_directory ( string $bucket, string $dir, $opt = [] ) : array 将目录中的所有文件进行上传,每个文件为单独object,object命名方式下详: 如有 /home/worker/a/b/c.txt 需上传目录为$dir=/home/worker/a object命令方式为 1. object默认命名方式为 “子目录名 +文件名”,如上述文件c.txt,默认为 '/b/c.txt' 2. 增强命名模式,在$opt中有可选参数进行配置 举例说明 :prefix . has_sub_directory?"/b":"" . '/c.txt'
validate_bucket ( string $bucket ) : boolean 校验bucket是否合法,bucket规范 1. 由小写字母,数字和横线'-'组成,长度为6~63位 2. 不能以数字作为Bucket开头 3. 不能以'-'作为Bucket的开头或者结尾
validate_object ( string $object ) : boolean 校验object是否合法,object命名规范 1. object必须以'/'开头

Private Methods

Method Description
analyze_user_acl ( string | array $acl ) : array 根据用户传入的acl,进行相应的处理 (1).设置详细json格式的acl; a. $acl 为json的array b. $acl 为json的string (2).通过acl_type字段进行设置
array_recursive ( &$array, string $function, boolean $apply_to_keys_also = false ) 使用特定function对数组中所有元素做处理
array_to_json ( array $array ) 由数组构造json字符串,增加了一些特殊处理以支持特殊字符和不同编码的中文
assertParameterArray ( $opt ) make sure $opt is an array
authenticate ( array $opt ) : BCS_ResponseCore 将消息发往Baidu BCS.
check_user_acl ( array $acl ) : string 检查用户输入的acl array是否合法,并转为json
format_signature ( array $opt ) : boolean | string 生成签名
format_url ( array $opt ) : boolean | string 构造url
generate_user_url ( $method, $bucket, $object, $opt = [] ) 生成签名链接
set_header_into_opt ( string $header, string $value, array &$opt ) : void 将常用set http-header的动作抽离出来

Method Details

__construct() public method

构造函数
public __construct ( string $ak = null, string $sk = null, string $hostname = null )
$ak string 云存储公钥
$sk string 云存储私钥
$hostname string 云存储Api访问地址

copy_object() public method

通过此方法以拷贝的方式创建object,object来源为$source
public copy_object ( array $source, array $dest, array $opt = [] ) : BCS_ResponseCore
$source array (Required) object 来源 bucket(Required) object(Required)
$dest array (Required) 待拷贝的目标object bucket(Required) object(Required)
$opt array (Optional) source_tag 指定拷贝对象的版本号
return BCS_ResponseCore

create_bucket() public method

创建 bucket
public create_bucket ( string $bucket, string $acl = null, array $opt = [] ) : BCS_ResponseCore
$bucket string (Required) bucket名称
$acl string (Optional) bucket权限设置,若为null,使用server分配的默认权限
$opt array (Optional)
return BCS_ResponseCore

create_object() public method

上传文件
public create_object ( string $bucket, string $object, string $file, array $opt = [] ) : BCS_ResponseCore
$bucket string (Required)
$object string (Required)
$file string (Required); 需要上传的文件的文件路径
$opt array (Optional) filename - Optional; 指定文件名 acl - Optional ; 上传文件的acl,只能使用acl_type seekTo - Optional; 上传文件的偏移位置 length - Optional; 待上传长度
return BCS_ResponseCore

create_object_by_content() public method

上传文件
public create_object_by_content ( string $bucket, string $object, $content, array $opt = [] ) : BCS_ResponseCore
$bucket string (Required)
$object string (Required)
$opt array (Optional) filename - Optional; 指定文件名 acl - Optional ; 上传文件的acl,只能使用acl_type
return BCS_ResponseCore

create_object_superfile() public method

通过superfile的方式上传文件
public create_object_superfile ( string $bucket, string $object, string $file, array $opt = [] ) : BCS_ResponseCore
$bucket string (Required)
$object string (Required)
$file string (Required); 需要上传的文件的文件路径
$opt array (Optional) filename - Optional; 指定文件名 sub_object_size - Optional; 指定子文件的划分大小,单位B,建议以256KB为单位进行子object划分,默认为1MB进行划分
return BCS_ResponseCore

delete_bucket() public method

删除bucket
public delete_bucket ( string $bucket, array $opt = [] ) : boolean | BCS_ResponseCore
$bucket string (Required)
$opt array (Optional)
return boolean | BCS_ResponseCore

delete_object() public method

删除object
public delete_object ( string $bucket, string $object, array $opt = [] ) : BCS_ResponseCore
$bucket string (Required)
$object string (Required)
$opt array (Optional)
return BCS_ResponseCore

generate_delete_object_url() public method

生成delete_object的url
public generate_delete_object_url ( string $bucket, string $object, $opt = [] )
$bucket string (Required)
$object string (Required) return false| string url

generate_get_object_url() public method

生成get_object的url
public generate_get_object_url ( string $bucket, string $object, $opt = [] )
$bucket string (Required)
$object string (Required) return false| string url

generate_head_object_url() public method

生成head_object的url
public generate_head_object_url ( string $bucket, string $object, $opt = [] )
$bucket string (Required)
$object string (Required) return false| string url

generate_post_object_url() public method

生成post_object的url
public generate_post_object_url ( string $bucket, string $object, $opt = [] )
$bucket string (Required)
$object string (Required) return false| string url

generate_put_object_url() public method

生成put_object的url
public generate_put_object_url ( string $bucket, string $object, $opt = [] )
$bucket string (Required)
$object string (Required) return false| string url

getUse_ssl() public method

public getUse_ssl ( ) : the
return the $use_ssl

get_bucket_acl() public method

获取bucket的acl
public get_bucket_acl ( string $bucket, array $opt = [] ) : BCS_ResponseCore
$bucket string (Required)
$opt array (Optional)
return BCS_ResponseCore

get_filetree() public static method

获取传入目录的文件列表
public static get_filetree ( string $dir, $file_prefix = "/*" ) : array
$dir string 文件目录
return array 文件树

get_object() public method

下载object
public get_object ( string $bucket, string $object, array $opt = [] ) : BCS_ResponseCore
$bucket string (Required)
$object string (Required)
$opt array (Optional) fileWriteTo (Optional)直接将请求结果写入该文件,如果fileWriteTo文件存在,sdk进行重命名再存储
return BCS_ResponseCore

get_object_acl() public method

获取object的acl
public get_object_acl ( string $bucket, string $object, array $opt = [] ) : BCS_ResponseCore
$bucket string (Required)
$object string (Required)
$opt array (Optional)
return BCS_ResponseCore

get_object_info() public method

获取文件信息,发送的为HTTP HEAD请求,文件信息都在http response的header中,不会提取文件的内容
public get_object_info ( string $bucket, string $object, array $opt = [] ) : array
$bucket string (Required)
$object string (Required)
$opt array (Optional)
return array BCS_ResponseCore

is_object_exist() public method

判断object是否存在
public is_object_exist ( string $bucket, string $object, array $opt = [] ) : boolean
$bucket string (Required)
$object string (Required)
$opt array (Optional)
return boolean true|boolean false|BCS_ResponseCore true:object存在 false:不存在 BCS_ResponseCore其他错误

list_bucket() public method

获取当前密钥对拥有者的bucket列表
public list_bucket ( array $opt = [] ) : BCS_ResponseCore
$opt array (Optional) BaiduBCS::IMPORT_BCS_LOG_METHOD - String - Optional: 支持用户传入日志处理函数,函数定义如 function f($log)
return BCS_ResponseCore

list_object() public method

获取bucket中object列表
public list_object ( string $bucket, array $opt = [] ) : BCS_ResponseCore
$bucket string (Required)
$opt array (Optional) start : 主要用于翻页功能,用法同mysql中start的用法 limit : 主要用于翻页功能,用法同mysql中limit的用法 prefix: 只返回以prefix为前缀的object,此处prefix必须以'/'开头
return BCS_ResponseCore

list_object_by_dir() public method

以目录形式获取bucket中object列表
public list_object_by_dir ( string $bucket, $dir = '/', string $list_model = 2, array $opt = [] ) : BCS_ResponseCore
$bucket string (Required)
$dir (Required) 目录名,格式为必须以'/'开头和结尾,默认为'/'
$list_model string (Required) 目录展现形式,值可以为0,1,2,默认为2,以下对各个值的功能进行介绍: 0->只返回object列表,不返回子目录列表 1->只返回子目录列表,不返回object列表 2->同时返回子目录列表和object列表
$opt array (Optional) start : 主要用于翻页功能,用法同mysql中start的用法 limit : 主要用于翻页功能,用法同mysql中limit的用法
return BCS_ResponseCore

log() public method

内置的日志函数,可以根据用户传入的log函数,进行日志输出
public log ( string $log, array $opt )
$log string
$opt array

setUse_ssl() public method

public setUse_ssl ( boolean $use_ssl )
$use_ssl boolean

set_bucket_acl() public method

设置bucket的acl,有三种模式, (1).设置详细json格式的acl; a. $acl 为json的array b. $acl 为json的string (2).通过acl_type字段进行设置 a. $acl 为BaiduBCS::$ACL_TYPES中的字段
public set_bucket_acl ( string $bucket, string $acl, array $opt = [] ) : boolean | BCS_ResponseCore
$bucket string (Required)
$acl string (Required)
$opt array (Optional)
return boolean | BCS_ResponseCore

set_object_acl() public method

设置object的acl,有三种模式, (1).设置详细json格式的acl; a. $acl 为json的array b. $acl 为json的string (2).通过acl_type字段进行设置 a. $acl 为BaiduBCS::$ACL_ACTIONS中的字段
public set_object_acl ( string $bucket, string $object, string | array $acl, array $opt = [] ) : BCS_ResponseCore
$bucket string (Required)
$object string (Required)
$acl string | array (Required)
$opt array (Optional)
return BCS_ResponseCore

set_object_meta() public method

设置object的meta信息
public set_object_meta ( string $bucket, string $object, $meta, array $opt = [] ) : BCS_ResponseCore
$bucket string (Required)
$object string (Required)
$opt array (Optional) 目前支持的meta信息如下: Content-Type Cache-Control Content-Disposition Content-Encoding Content-MD5 Expires
return BCS_ResponseCore

trimUrl() public static method

将url中 '//' 替换为 '/'
public static trimUrl ( $url ) : string
$url
return string

upload_directory() public method

将目录中的所有文件进行上传,每个文件为单独object,object命名方式下详: 如有 /home/worker/a/b/c.txt 需上传目录为$dir=/home/worker/a object命令方式为 1. object默认命名方式为 “子目录名 +文件名”,如上述文件c.txt,默认为 '/b/c.txt' 2. 增强命名模式,在$opt中有可选参数进行配置 举例说明 :prefix . has_sub_directory?"/b":"" . '/c.txt'
public upload_directory ( string $bucket, string $dir, $opt = [] ) : array
$bucket string (Required)
$dir string (Required)
return array 数组形式的上传结果 'success' => int 上传成功的文件数目 'skipped' => int 被跳过的文件 'failed' => array() 上传失败的文件

validate_bucket() public static method

校验bucket是否合法,bucket规范 1. 由小写字母,数字和横线'-'组成,长度为6~63位 2. 不能以数字作为Bucket开头 3. 不能以'-'作为Bucket的开头或者结尾
public static validate_bucket ( string $bucket ) : boolean
$bucket string
return boolean

validate_object() public static method

校验object是否合法,object命名规范 1. object必须以'/'开头
public static validate_object ( string $object ) : boolean
$object string
return boolean

Property Details

$ACL_ACTIONS public_oe static_oe property

public static $ACL_ACTIONS

$ACL_EFFECTS public_oe static_oe property

public static $ACL_EFFECTS

$ACL_TYPES public_oe static_oe property

SDK中开放此上五种acl_tpe
public static $ACL_TYPES

$use_ssl protected_oe property

是否使用ssl
protected $use_ssl