php七牛云,php七牛云

标签:token   dmg   access   tmg   space   ora   qiniu   path   link

namespace lib;

use think\Loader;

/**

* Description of Qrcode

*

* @author lsf

*/

class Qiniu {

private $bucket;

private $uploadMgr;

private $qiniuyunlink;

private $bucketMgr;

/**

* 初始化上传

* @param type $seeting=array("access_key"=>"七牛key","secret_key"=>"七牛secret","bucket"=>"七牛空间","qiniuyunlink"=>"七牛云域名")

*/

public function __construct($seeting) {

Loader::import("qiniu/autoload", EXTEND_PATH);

$auth = new \Qiniu\Auth($seeting["access_key"], $seeting["secret_key"]);

$this->qiniuyunlink = $seeting["qiniuyunlink"];

$this->bucket = $auth->uploadToken($seeting["bucket"]);

$this->uploadMgr = new \Qiniu\Storage\UploadManager();

$this->bucketMgr = new \Qiniu\Storage\BucketManager($auth);

}

/**

* 七牛云文件上传

* @param type $file

*/

public function upload($file) {

$filePath = $file[‘tmp_name‘];

$name = date("YmdHis", time()) . rand(100000, 999999);

if ($file[‘type‘] == ‘video/mp4‘) {

$key = ‘video‘ . $name . ‘.mp4‘;

} elseif ($file[‘type‘] == ‘audio/mp3‘||$file[‘type‘] == ‘audio/mpeg‘) {

$key = ‘audio‘ . $name . ‘.mp3‘;

} else {

$key = ‘png‘ . $name . ‘.png‘;

}

list($ret, $err) = $this->uploadMgr->putFile($this->bucket, $key, $filePath);

if ($err !== null) {

return array("success" => false, "msg" => "文件上传失败");

} else {

return array("success" => true, "msg" => "", "path" => $ret[‘key‘]);

}

}

/**

* 获取uploadToken

* @param type $link 直接是不带域名的文件名

*/

public function uploadToken() {

return $this->bucket;

}

/**

* 七牛云文件删除

* @param type $link 直接是不带域名的文件名

*/

public function fileDel($link) {

if (!empty($link)) {

$re = $this->bucketMgr->delete($this->bucket, $link);

if (empty($re)) {

return array("success" => true, "msg" => "", "data" => "");

} else {

return array("success" => false, "msg" => $re, "data" => "");

}

}

return array("success" => true, "msg" => "", "data" => "");

}

}

php七牛云

标签:token   dmg   access   tmg   space   ora   qiniu   path   link

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值