PHP Class UpYun, shudong-share

Show file Open project: HFO4/shudong-share Class Usage Examples

Protected Properties

Property Type Description
$endpoint

Public Methods

Method Description
__construct ( $bucketname, $username, $password, $endpoint = NULL, $timeout = 30 ) : object 初始化 UpYun 存储接口
delete ( string $path ) : boolean 删除目录和文件
deleteFile ( string $path ) : boolean 删除文件
getBucketUsage ( ) : mixed 获取空间使用情况
getFileInfo ( string $path ) : mixed 获取文件、目录信息
getFolderUsage ( string $path = '/' ) : mixed
getList ( string $path = '/' ) : mixed 获取目录文件列表
getWritedFileInfo ( $key )
getXRequestId ( )
makeDir ( $path, $auto_mkdir = false ) : void 创建目录
readDir ( string $path ) : array 获取目录文件列表
readFile ( string $path, mixed $file_handle = NULL ) : mixed 下载文件
rmDir ( $path ) : void 删除目录
setApiDomain ( $domain ) 切换 API 接口的域名
setContentMD5 ( $str ) 设置待上传文件的 Content-MD5 值(如又拍云服务端收到的文件MD5值与用户设置的不一致,将回报 406 Not Acceptable 错误)
setFileSecret ( $str ) 设置待上传文件的 访问密钥(注意:仅支持图片空!,设置密钥后,无法根据原文件URL直接访问,需带 URL 后面加上 (缩略图间隔标志符+密钥) 进行访问) 如缩略图间隔标志符为 ! ,密钥为 bac,上传文件路径为 /folder/test.jpg ,那么该图片的对外访问地址为: http://空间域名/folder/test.jpg!bac
version ( ) 获取当前SDK版本号
writeFile ( string $path, mixed $file, boolean $auto_mkdir = False, array $opts = NULL ) 上传文件

Protected Methods

Method Description
_do_request ( string $method, string $path, array $headers = NULL, array $body = NULL, $file_handle = NULL ) : mixed HTTP REQUEST 封装

Private Methods

Method Description
_getErrorMessage ( string $header_string ) : mixed 获取返回的错误信息
_getHeadersData ( string $text ) : array 处理HTTP HEADERS中返回的自定义数据
setXRequestId ( $header_string )
sign ( $method, $uri, $date, $length ) 连接签名方法

Method Details

__construct() public method

初始化 UpYun 存储接口
public __construct ( $bucketname, $username, $password, $endpoint = NULL, $timeout = 30 ) : object
$bucketname 空间名称
$username 操作员名称
$password 密码
return object

_do_request() protected method

HTTP REQUEST 封装
protected _do_request ( string $method, string $path, array $headers = NULL, array $body = NULL, $file_handle = NULL ) : mixed
$method string HTTP REQUEST方法,包括PUT、POST、GET、OPTIONS、DELETE
$path string 除Bucketname之外的请求路径,包括get参数
$headers array 请求需要的特殊HTTP HEADERS
$body array 需要POST发送的数据
return mixed

delete() public method

删除目录和文件
public delete ( string $path ) : boolean
$path string 路径
return boolean

deleteFile() public method

删除文件
Deprecation:
public deleteFile ( string $path ) : boolean
$path string 要删除的文件路径
return boolean

getBucketUsage() public method

获取空间使用情况
Deprecation: 推荐直接使用 getFolderUsage('/')来获取
public getBucketUsage ( ) : mixed
return mixed

getFileInfo() public method

获取文件、目录信息
public getFileInfo ( string $path ) : mixed
$path string 路径
return mixed

getFolderUsage() public method

Deprecation:
public getFolderUsage ( string $path = '/' ) : mixed
$path string 目录路径
return mixed

getList() public method

获取目录文件列表
public getList ( string $path = '/' ) : mixed
$path string 查询路径
return mixed

getWritedFileInfo() public method

Deprecation: 获取上传文件后的信息(仅图片空间有返回数据)
public getWritedFileInfo ( $key )
$key 信息字段名(x-upyun-width、x-upyun-height、x-upyun-frames、x-upyun-file-type) return value or NULL

getXRequestId() public method

public getXRequestId ( )

makeDir() public method

创建目录
public makeDir ( $path, $auto_mkdir = false ) : void
$path 路径
$auto_mkdir 是否自动创建父级目录,最多10层次
return void

readDir() public method

获取目录文件列表
Deprecation:
public readDir ( string $path ) : array
$path string 要获取列表的目录
return array

readFile() public method

下载文件
public readFile ( string $path, mixed $file_handle = NULL ) : mixed
$path string 文件路径
$file_handle mixed
return mixed

rmDir() public method

删除目录
Deprecation:
public rmDir ( $path ) : void
$path 路径
return void

setApiDomain() public method

切换 API 接口的域名
Deprecation:
public setApiDomain ( $domain )
$domain {默然 v0.api.upyun.com 自动识别, v1.api.upyun.com 电信, v2.api.upyun.com 联通, v3.api.upyun.com 移动} return null;

setContentMD5() public method

设置待上传文件的 Content-MD5 值(如又拍云服务端收到的文件MD5值与用户设置的不一致,将回报 406 Not Acceptable 错误)
Deprecation:
public setContentMD5 ( $str )
$str (文件 MD5 校验码) return null;

setFileSecret() public method

设置待上传文件的 访问密钥(注意:仅支持图片空!,设置密钥后,无法根据原文件URL直接访问,需带 URL 后面加上 (缩略图间隔标志符+密钥) 进行访问) 如缩略图间隔标志符为 ! ,密钥为 bac,上传文件路径为 /folder/test.jpg ,那么该图片的对外访问地址为: http://空间域名/folder/test.jpg!bac
Deprecation:
public setFileSecret ( $str )
$str (文件 MD5 校验码) return null;

version() public method

获取当前SDK版本号
public version ( )

writeFile() public method

上传文件
public writeFile ( string $path, mixed $file, boolean $auto_mkdir = False, array $opts = NULL )
$path string 存储路径
$file mixed 需要上传的文件,可以是文件流或者文件内容
$auto_mkdir boolean 自动创建目录
$opts array 可选参数

Property Details

$endpoint protected property

protected $endpoint