构造函数
$_accessKey与$_secretKey可以为空,为空的情况下可以认为是公开读文件
void
__construct
([string $_accessKey = ''], [string $_secretKey = ''])
-
string
$_accessKey
-
string
$_secretKey
删除文件
bool
delete
(string $domain, string $filename)
-
string
$domain
-
string
$filename
返回运行过程中的错误信息
string
errmsg
()
返回运行过程中的错误代码
int
errno
()
检查文件是否存在
array
fileExists
(string $domain, string $filename)
-
string
$domain
-
string
$filename
获取文件属性
array
getAttr
(string $domain, string $filename, [array $attrKey = array()])
-
string
$domain
-
string
$filename
-
array
$attrKey: 属性值,如 array("fileName", "length"),当attrKey为空时,以关联数组方式返回该文件的所有属性。
获取指定domain下的文件名列表
//遍历Domain下所有文件
$num = 0;
while ( $ret =
$obj->getList("test", "*", 100, $num ) ) {
foreach($ret as $file) {
echo "{$file}\n";
$num ++;
}
}
echo "\nTOTAL: {$num} files\n";
array
getList
(string $domain, [string $prefix = '*'], [int $limit = 10], [int $skip = 0])
-
string
$domain: 存储域,在在线管理平台.storage页面可进行管理
-
string
$prefix: 如 *,abc*,*.txt
-
int
$limit: 返回条数,最大100条,默认10条
-
int
$skip: 起始条数。
取得访问存储文件的url
string
getUrl
(string $domain, string $filename)
-
string
$domain
-
string
$filename
获取文件的内容
mixxed
read
(string $domain, string $filename)
-
string
$domain
-
string
$filename
设置key
当需要访问其他APP的数据时使用
void
setAuth
(string $akey, string $skey)
-
string
$akey
-
string
$skey
设置Domain属性
目前支持的Domain属性
- expires: 浏览器缓存超时,功能与Apache的Expires配置相同
$expires = 'ExpiresActive On
ExpiresDefault "access plus 30 days"
ExpiresByType text/html "access plus 1 month 15 days 2 hours"
ExpiresByType image/gif "modification plus 5 hours 3 minutes"
ExpiresByType image/jpg A2592000
ExpiresByType text/plain M604800
';
$attr = array('expires'=>$expires);
if ($ret === false) {
}
bool
setDomainAttr
(string $domain, [array $attr = array()])
-
string
$domain
-
array
$attr: Domain属性。格式:array('attr0'=>'value0', 'attr1'=>'value1', ......);
设置文件属性
目前支持的文件属性
- expires: 浏览器缓存超时,功能与Apache的Expires配置相同
- encoding: 设置通过Web直接访问文件时,Header中的Content-Encoding。
- type: 设置通过Web直接访问文件时,Header中的Content-Type。
$attr = array('expires' => 'access plus 1 year');
if ($ret === false) {
}
$attr = array('expires' => 'A3600');
$ret =
$stor->setFileAttr("test", "expire/*.txt", $attr);
if ($ret === false) {
}
bool
setFileAttr
(string $domain, string $filename, [array $attr = array()])
-
string
$domain
-
string
$filename: 文件名,可以使用通配符"*"和"?"
-
array
$attr: 文件属性。格式:array('attr0'=>'value0', 'attr1'=>'value1', ......);
将文件上传入存储
string
upload
(string $domain, string $destFile, string $srcFile, [array $attr = array()], [bool $compress = false])
-
string
$domain: 存储域,在在线管理平台.storage页面可进行管理
-
string
$destFile: 目标文件名
-
string
$srcFile: 源文件名
-
array
$attr: 文件属性,可设置的属性请参考 SaeStorage::setFileAttr() 方法
-
bool
$compress: 是否gzip压缩。如果设为true,则文件会经过gzip压缩后再存入Storage,常与$attr=array('encoding'=>'gzip')联合使用
将数据写入存储
string
write
(string $domain, string $destFile, string $content, [int $size = -1], [array $attr = array()], [bool $compress = false])
-
string
$domain: 存储域,在在线管理平台.storage页面可进行管理
-
string
$destFile: 文件名
-
string
$content: 文件内容,支持二进制数据
-
int
$size: 写入长度,默认为不限制
-
array
$attr: 文件属性,可设置的属性请参考 SaeStorage::setFileAttr() 方法
-
bool
$compress: 是否gzip压缩。如果设为true,则文件会经过gzip压缩后再存入Storage,常与$attr=array('encoding'=>'gzip')联合使用