首先 需要注册 https://portal.qiniu.com 然后认证
然后 https://portal.qiniu.com/create 选择对象存储 然后创建一个空间
下载sdk https://developer.qiniu.com/kodo/sdk/1241/php
直接贴代码
<?php
namespace app\admin\controller;
vendor('Qiniu.autoload');
use Qiniu\Auth as Auth;
use Qiniu\Storage\BucketManager;
use Qiniu\Storage\UploadManager;
use think\Controller;
class VideoUpload extends controller {
private static secretKey="";//秘钥
private static bucket='zsj-yangdongdong';//存储空间
function uploadvideo(){
accessKey, self::token = bucket);//生成token
_FILES);
_FILES['image']['tmp_name'];//本地路径
if(key = 'video'.time().'.mp4';
}else{
echo "文件格式不正确";
}
list(err) = token, filePath);
if (ret['key']);
}
}
public function upload(){
return auth = new Auth(self::secretKey);//实例化
baseUrl."video1542003761.mp4";//拼接字符串
auth->privateDownloadUrl(this->assign("url",this->fetch();
}
//删除
public function del(){
accessKey,self::buck= new BucketManager(flag=bucket,"png1542004391.png");
if (is_null($flag)) {
echo "success";
}else{
echo "error";
}
}
}
这里用的是tp5 都是一些基本的上传 阅读 删除功能 实际开发中需要自己根据需求修改
网友评论