Git Product home page Git Product logo

php-saestorage's Introduction

PHP SDK For SAE Storage

此版本PHP SDK 不依赖于SAE WEB runtime,可以在远程使用SAE提供的云存储服务.

我们鼓励对于运行在SAE上的应用仍然使用我们集成在runtime中的storage api操作storage中存储的文件,但如果您有在您自己主机上使用 我们提供的云存储服务时您可以使用这个PHP SDK.

获取domain列表

<?php
require_once('saestorage.class.php');
#your app accesskey
$ak = 'k5nmzy5445';
#your app secretkey
$sk = 'lzxkxy0x2iyili3k113iiw1mz5kimlwk33j5wyl1';
$storage = new SaeStorage($ak, $sk);
$domList = $storage->lsdom();
print_r($domList);
?>

获取指定domain文件列表

<?php
require_once('saestorage.class.php');
#your app accesskey
$ak = 'k5nmzy5445';
#your app secretkey
$sk = 'lzxkxy0x2iyili3k113iiw1mz5kimlwk33j5wyl1';
#your domain name
$domain = 'lazy';
$fileList = $storage->getList($domain);
print_r($fileList);
?>

写入一个文件

<?php
require_once('saestorage.class.php');
#your app accesskey
$ak = 'k5nmzy5445';
#your app secretkey
$sk = 'lzxkxy0x2iyili3k113iiw1mz5kimlwk33j5wyl1';
#your domain name
$domain = 'lazy';
$destFileName = 'write_test.txt';
$content = 'Hello,I am from the method of write';
$attr = array('encoding'=>'gzip');
$storage = new SaeStorage($ak, $sk);
$result = $storage->write($domain,$destFileName, $content, -1, $attr, true);
var_dump($result);
?>

获取一个文件URL地址

<?php
require_once('saestorage.class.php');
#your app accesskey
$ak = 'k5nmzy5445';
#your app secretkey
$sk = 'lzxkxy0x2iyili3k113iiw1mz5kimlwk33j5wyl1';
#your domain name
$domain = 'lazy';
$fileName = 'write_test.txt';
$storage = new SaeStorage($ak, $sk);
$fileUrl = $storage->getUrl($domain,$fileName);
var_dump($fileUrl);
?>

获取一个文件CDN URL地址(需要在SAE管理平台开启CDN)

<?php
require_once('saestorage.class.php');
#your app accesskey
$ak = 'k5nmzy5445';
#your app secretkey
$sk = 'lzxkxy0x2iyili3k113iiw1mz5kimlwk33j5wyl1';
#your domain name
$domain = 'lazy';
$fileName = 'write_test.txt';
$storage = new SaeStorage($ak, $sk);
$fileUrl = $storage->getCDNUrl($domain,$fileName);
var_dump($fileUrl);
?>

获取文件的属性

<?php
require_once('saestorage.class.php');
#your app accesskey
$ak = 'k5nmzy5445';
#your app secretkey
$sk = 'lzxkxy0x2iyili3k113iiw1mz5kimlwk33j5wyl1';
#your domain name
$domain = 'lazy';
#your file name
$filename = 'interface.txt';
$storage = new SaeStorage($ak, $sk);
$fileAttr = $storage->getAttr($domain,$filename);
var_dump($fileAttr);
?>

读取一个文件内容

<?php
require_once('saestorage.class.php');
#your app accesskey
$ak = 'k5nmzy5445';
#your app secretkey
$sk = 'lzxkxy0x2iyili3k113iiw1mz5kimlwk33j5wyl1';
#your domain name
$domain = 'lazy';
#your file name
$filename = 'interface.txt';
$storage = new SaeStorage($ak, $sk);
$fileContent = $storage->read($domain,$filename);
var_dump($fileContent);
?>

删除一个文件

<?php
require_once('saestorage.class.php');
#your app accesskey
$ak = 'k5nmzy5445';
#your app secretkey
$sk = 'lzxkxy0x2iyili3k113iiw1mz5kimlwk33j5wyl1';
#your domain name
$domain = 'lazy';
#your file name
$filename = 'interface.txt';
$storage = new SaeStorage($ak, $sk);
$deleteResult = $storage->delete($domain,$filename);
var_dump($deleteResult);
?>

设置文件属性

<?php
require_once('saestorage.class.php');
#your app accesskey
$ak = 'k5nmzy5445';
#your app secretkey
$sk = 'lzxkxy0x2iyili3k113iiw1mz5kimlwk33j5wyl1';
#your domain name
$domain = 'lazy';
#your file name
$filename = 'interface.txt';
$attr = array('expires' => 'access plus 1 year');
$storage = new SaeStorage($ak, $sk);
$setAttrResult = $storage->setFileAttr($domain,$filename,$attr);
var_dump($setAttrResult);
?>

设置domain属性

<?php
require_once('saestorage.class.php');
#your app accesskey
$ak = 'k5nmzy5445';
#your app secretkey
$sk = 'lzxkxy0x2iyili3k113iiw1mz5kimlwk33j5wyl1';
#your domain name
$domain = 'lazy';
$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
';
$allowReferer['hosts'][] = 'lazydemo.sinaapp.com';
$allowReferer['hosts'][] = '*.lazydemo.sinaapp.com';
$allowReferer['redirect'] = 'http://lazydemo.sinaapp.com/';
$tag = array('hellotag');
$attr = array('expires'=>$expires, 'allowReferer'=>$allowReferer,'tag'=>$tag);
$storage = new SaeStorage($ak, $sk);
$setDomainAttrResult = $storage->setDomainAttr($domain,$attr);
var_dump($setDomainAttrResult);
?>

获取domain下的文件总数

<?php
require_once('saestorage.class.php');
#your app accesskey
$ak = 'k5nmzy5445';
#your app secretkey
$sk = 'lzxkxy0x2iyili3k113iiw1mz5kimlwk33j5wyl1';
#your domain name
$domain = 'lazy';
$storage = new SaeStorage($ak, $sk);
$filesNum = $storage->getFilesNum($domain);
var_dump($filesNum);
?>

获取domain的容量信息

<?php
require_once('saestorage.class.php');
#your app accesskey
$ak = 'k5nmzy5445';
#your app secretkey
$sk = 'lzxkxy0x2iyili3k113iiw1mz5kimlwk33j5wyl1';
#your domain name
$domain = 'lazy';
$storage = new SaeStorage($ak, $sk);
$filesNum = $storage->getDomainCapacity($domain);
var_dump($filesNum);
?>

判断文件是否存在

<?php
require_once('saestorage.class.php');
#your app accesskey
$ak = 'k5nmzy5445';
#your app secretkey
$sk = 'lzxkxy0x2iyili3k113iiw1mz5kimlwk33j5wyl1';
#your domain name
$domain = 'lazy';
#your file name
$filename_exist = 'interface.txt';
$fikename_notexist = 'interface2.txt';
$storage = new SaeStorage($ak, $sk);
$exist = $storage->fileExists($domain,$filename_exist);
$not_exist = $storage->fileExists($domain,$fikename_notexist);
var_dump($exist,$not_exist);
?>

Bug tracker

Have a bug? Please create an issue here on GitHub!

https://github.com/xiaosier/php-saestorage/issues

Authors

License

Copyright 2011 SINA, Inc. Copyright 2011 SAE

Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0

php-saestorage's People

Contributors

xiaosier avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.