|
@@ -9,7 +9,7 @@ class Qiniu
|
|
|
private $client;
|
|
|
private $token;
|
|
|
|
|
|
- public function token($config, $upload, $file = '')
|
|
|
+ public function token($config, $upload, $file = false)
|
|
|
{
|
|
|
$cur = time();
|
|
|
//if (!$config['token'] || ($config['token_endtime'] && $cur > $config['token_endtime'])) {
|
|
@@ -46,7 +46,7 @@ class Qiniu
|
|
|
}
|
|
|
|
|
|
# 连接
|
|
|
- public function connect($config, $upload, $file = '')
|
|
|
+ public function connect($config, $upload, $file = false)
|
|
|
{
|
|
|
list($type, $token, $domain, $bucket) = $this->token($config, $upload, $file);
|
|
|
$this->token = $token;
|
|
@@ -55,6 +55,25 @@ class Qiniu
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
+ # 下载文件
|
|
|
+ public function download($bucket, $file, $local = false)
|
|
|
+ {
|
|
|
+ if (!$this->client) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if ($local) {
|
|
|
+ $options = array(
|
|
|
+ OssClient::OSS_FILE_DOWNLOAD => $local
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ $options = array();
|
|
|
+ }
|
|
|
+
|
|
|
+ $content = $this->client->getObject($bucket, $file, $options);
|
|
|
+
|
|
|
+ return $content;
|
|
|
+ }
|
|
|
+
|
|
|
# 上传文件
|
|
|
public function upload($file, $source_file, $options = array(), $base64 = false)
|
|
|
{
|