Class SaeStorage

Description

SaeStorage class

  1.  $s new SaeStorage();
  2.  $s->write'example' 'thebook' 'bookcontent!' );
  3.  
  4.  echo $s->read'example' 'thebook';
  5.  // will echo 'bookcontent!';
  6.  
  7.  echo $s->getUrl'example' 'thebook' );
  8.  // will echo 'http://exampale.stor.sinaapp.com/thebook';

常见错误码参考:

  • errno: 0 成功
  • errno: -2 配额统计错误
  • errno: -3 权限不足
  • errno: -12 存储服务器返回错误
  • errno: -18 文件不存在
  • errno: -101 参数错误
  • errno: -102 存储服务器连接失败

  • author: quanjun

Located in /saestorage.class.php (line 40)

SaeObject
   |
   --SaeStorage
Method Summary
void __construct ([string $_accessKey = ''], [string $_secretKey = ''])
bool delete (string $domain, string $filename)
string errmsg ()
int errno ()
array fileExists (string $domain, string $filename)
array getAttr (string $domain, string $filename, [array $attrKey = array()])
array getList (string $domain, [string $prefix = '*'], [int $limit = 10], [int $skip = 0])
string getUrl (string $domain, string $filename)
mixxed read (string $domain, string $filename)
void setAuth (string $akey, string $skey)
bool setDomainAttr (string $domain, [array $attr = array()])
bool setFileAttr (string $domain, string $filename, [array $attr = array()])
string upload (string $domain, string $destFile, string $srcFile, [array $attr = array()], [bool $compress = false])
string write (string $domain, string $destFile, string $content, [int $size = -1], [array $attr = array()], [bool $compress = false])
Methods
Constructor __construct (line 103)

构造函数

$_accessKey与$_secretKey可以为空,为空的情况下可以认为是公开读文件

  • author: Elmer Zhang
  • access: public
void __construct ([string $_accessKey = ''], [string $_secretKey = ''])
  • string $_accessKey
  • string $_secretKey
delete (line 435)

删除文件

  • author: Elmer Zhang
  • access: public
bool delete (string $domain, string $filename)
  • string $domain
  • string $filename
errmsg (line 133)

返回运行过程中的错误信息

  • author: Elmer Zhang
  • access: public
string errmsg ()
errno (line 147)

返回运行过程中的错误代码

  • author: Elmer Zhang
  • access: public
int errno ()
fileExists (line 368)

检查文件是否存在

  • author: Elmer Zhang
  • access: public
array fileExists (string $domain, string $filename)
  • string $domain
  • string $filename
getAttr (line 331)

获取文件属性

  • author: Elmer Zhang
  • access: public
array getAttr (string $domain, string $filename, [array $attrKey = array()])
  • string $domain
  • string $filename
  • array $attrKey: 属性值,如 array("fileName", "length"),当attrKey为空时,以关联数组方式返回该文件的所有属性。
getList (line 293)

获取指定domain下的文件名列表

  1.  //遍历Domain下所有文件
  2.  $stor new SaeStorage();
  3.  
  4.  $num 0;
  5.  while $ret $obj->getList("test""*"100$num ) ) {
  6.          foreach($ret as $file{
  7.              echo "{$file}\n";
  8.              $num ++;
  9.          }
  10.  }
  11.  
  12.  echo "\nTOTAL: {$num} files\n";

  • return: 执行成功时返回文件列表数组,否则返回false
  • author: Elmer Zhang
  • access: public
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: 起始条数。
getUrl (line 162)

取得访问存储文件的url

  • author: Elmer Zhang
  • access: public
string getUrl (string $domain, string $filename)
  • string $domain
  • string $filename
read (line 395)

获取文件的内容

  • return: 文件内容
  • author: Elmer Zhang
  • access: public
mixxed read (string $domain, string $filename)
  • string $domain
  • string $filename
setAuth (line 121)

设置key

当需要访问其他APP的数据时使用

  • author: Elmer Zhang
  • access: public
void setAuth (string $akey, string $skey)
  • string $akey
  • string $skey
setDomainAttr (line 558)

设置Domain属性

目前支持的Domain属性

  • expires: 浏览器缓存超时,功能与Apache的Expires配置相同
  1.  $expires 'ExpiresActive On
  2.  ExpiresDefault "access plus 30 days"
  3.  ExpiresByType text/html "access plus 1 month 15 days 2 hours"
  4.  ExpiresByType image/gif "modification plus 5 hours 3 minutes"
  5.  ExpiresByType image/jpg A2592000
  6.  ExpiresByType text/plain M604800
  7.  ';
  8.  
  9.  $stor new SaeStorage();
  10.  
  11.  $attr array('expires'=>$expires);
  12.  $ret $stor->setDomainAttr("test"$attr);
  13.  if ($ret === false{
  14.          var_dump($stor->errno()$stor->errmsg());
  15.  }

  • author: Elmer Zhang
  • access: public
bool setDomainAttr (string $domain, [array $attr = array()])
  • string $domain
  • array $attr: Domain属性。格式:array('attr0'=>'value0', 'attr1'=>'value1', ......);
setFileAttr (line 494)

设置文件属性

目前支持的文件属性

  • expires: 浏览器缓存超时,功能与Apache的Expires配置相同
  • encoding: 设置通过Web直接访问文件时,Header中的Content-Encoding。
  • type: 设置通过Web直接访问文件时,Header中的Content-Type。
  1.  $stor new SaeStorage();
  2.  
  3.  $attr array('expires' => 'access plus 1 year');
  4.  $ret $stor->setFileAttr("test""test.txt"$attr);
  5.  if ($ret === false{
  6.          var_dump($stor->errno()$stor->errmsg());
  7.  }
  8.  
  9.  $attr array('expires' => 'A3600');
  10.  $ret $stor->setFileAttr("test""expire/*.txt"$attr);
  11.  if ($ret === false{
  12.          var_dump($stor->errno()$stor->errmsg());
  13.  }

  • author: Elmer Zhang
  • access: public
bool setFileAttr (string $domain, string $filename, [array $attr = array()])
  • string $domain
  • string $filename: 文件名,可以使用通配符"*"和"?"
  • array $attr: 文件属性。格式:array('attr0'=>'value0', 'attr1'=>'value1', ......);
upload (line 231)

将文件上传入存储

  • return: 写入成功时返回该文件的下载地址,否则返回false
  • author: Elmer Zhang
  • access: public
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')联合使用
write (line 196)

将数据写入存储

  • return: 写入成功时返回该文件的下载地址,否则返回false
  • author: Elmer Zhang
  • access: public
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')联合使用

Documentation generated on Wed, 11 Aug 2010 17:35:07 +0800 by phpDocumentor 1.4.3