<?php
namespace app\common\library\storage\engine;
use Qiniu\Auth;
use Qiniu\Storage\UploadManager;
use Qiniu\Storage\BucketManager;
class Qiniu extends Server
{
private $config;
public function __construct($config)
{
parent::__construct();
$this->config = $config;
}
public function upload()
{
$realPath = $this->getRealPath();
$auth = new Auth($this->config['access_key'], $this->config['secret_key']);
$token = $auth->uploadToken($this->config['bucket']);
$uploadMgr = new UploadManager();
list(, $error) = $uploadMgr->putFile($token, $this->fileName, $realPath);
if ($error !== null) {
$this->error = $error->message();
return false;
}
return true;
}
public function delete($fileName)
{
$auth = new Auth($this->config['access_key'], $this->config['secret_key']);
$bucketMgr = new BucketManager($auth);
$error = $bucketMgr->delete($this->config['bucket'], $fileName);
if ($error !== null) {
$this->error = $error->message();
return false;
}
return true;
}
public function getFileName()
{
return $this->fileName;
}
}