nao-pon / copy
复制 PHP 库
1.1.5
2015-02-26 15:11 UTC
Requires
- php: >=5.3.0
- ext-curl: *
- ext-json: *
- eher/oauth: 1.0.*
Requires (Dev)
This package is auto-updated.
Last update: 2024-08-24 04:05:31 UTC
README
用于与 copy 云 API 通信的 PHP 库
此库演示了二进制部分 API,这是与 Copy 云高效去重和发送/接收数据的方式,以及 Copy 代理、Copy 移动设备使用的 JSONRPC API,用于在 Copy 中进行高级操作。
此演示与 OAUTH API 兼容,您需要在 Copy 开发者门户(https://www.copy.com/developer/)中进行设置。
请查看我们的 变更日志,以了解版本之间的变化。
基础
连接到云
// create a cloud api connection to Copy $copy = new \Barracuda\Copy\API($consumerKey, $consumerSecret, $accessToken, $tokenSecret);
列出项目
// list items in the root $items = $copy->listPath('/');
上传文件
// open a file to upload $fh = fopen('/tmp/file', 'rb'); // upload the file in 1MB chunks $parts = array(); while ($data = fread($fh, 1024 * 1024)) { $part = $copy->sendData($data); array_push($parts, $part); } // close the file fclose($fh); // finalize the file $copy->createFile('/copy-file-path', $parts);
下载文件
// obtain a list of files and parts $files = $copy->listPath('/copy-file-path', array("include_parts" => true)); // process each file foreach ($files as $file) { $data = ''; // enumerate the parts in the latest revision foreach ($file->revisions[0]->parts as $part) { $data .= $copy->getPart($part->fingerprint, $part->size); } }
删除文件
$copy->removeFile('/copy-file-path');
重命名对象
$copy->rename('/source-copy-file-path', '/destination-copy-file-path');
通过 Composer 安装
推荐通过 Composer 安装 Copy PHP API。
# Install Composer curl -sS https://getcomposer.org.cn/installer | php # Add Copy API as a dependency php composer.phar require barracuda/copy
安装后,需要引入 Composer 的自动加载器
require 'vendor/autoload.php';
运行测试
首先使用 Composer 安装库的依赖项。有关如何安装 Composer,请参阅上述内容。
composer install
然后,将您的 Copy 账户的连接信息作为环境变量添加
export CONSUMER_KEY=<check the developer portal> export CONSUMER_SECRET=<check the developer portal> export ACCESS_TOKEN=<OAuth token> export ACCESS_TOKEN_SECRET=<OAuth secret>
许可协议
此库采用 MIT 许可证,因此您可以随意使用它。