首先去七牛云官网下载phpSDK工具放在Think/library/Vendor下。

ueditor后台调用方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
* 上传文件
* @param 
*/
public function UploadSomething(){
    header("Content-Type: text/html; charset=utf-8");
    error_reporting(E_ERROR);
    // 登录检测
    if($this->uid == 0){
        if($_GET['action'] == 'config'){
            echo preg_replace("/\/\*[\s\S]+?\*\//"""file_get_contents("./Public/js/php/config.json"));
        }else{
            echo json_encode(array('state'=> '请登录!'));
        }
        exit;
    }
    echo conditionChoice($this->uid);
}

放在ThinkPHP的Common.php中:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/**
* 条件选择
* @param 
*/
function conditionChoice($uid){
    $CONFIG = json_decode(preg_replace("/\/\*[\s\S]+?\*\//"""file_get_contents("./Public/js/php/config.json")), true);
    $action $_GET['action'];
 
    $Qiniu = C('QINIU');
    $domain $Qiniu['domain'];
     
    switch ($action){
        case 'config':
            $result =  json_encode($CONFIG);
            break;
        case 'uploadimage':
        case 'uploadscrawl':
        case 'uploadvideo':
        case 'uploadfile':
            $result = Upload($CONFIG,$uid);
            // 加上公网引用地址
            $result = json_decode($result,JSON_UNESCAPED_UNICODE);
            if(strtolower(strrchr($result['url'],'.')) != '.gif'){
                $result['url'] = $domain.$result['url'].'_600.jpg';
            }else{
                $result['url'] = $domain.$result['url'];
            }
            $result = json_encode($result,JSON_UNESCAPED_UNICODE);
            break;
        case 'listimage':
            $result = Lists($uid);
            break;
        case 'listfile':
            $result = json_encode(array('state'=> 'error 1000'));
            break;
        case 'catchimage':
            $result = json_encode(array('state'=> 'error 1001'));
            break;
        default:
            $result = json_encode(array(
                'state'=> '请求地址出错'
            ));
            break;
    }
    if(isset($_GET["callback"])){
        if(preg_match("/^[\w_]+$/"$_GET["callback"])){
            return htmlspecialchars($_GET["callback"]) . '(' $result ')';
        }else{
            return json_encode(array('state'=> 'callback参数不合法'));
        }
    }else{
        return $result;
    }
}
 
     
/**
* 获取文件列表
* @param 
*/
function Lists($uid){
    $limit = 40;
    $size = isset($_GET['size']) ? htmlspecialchars($_GET['size']) : $limit;
    $start = isset($_GET['start']) ? htmlspecialchars($_GET['start']) : 0;
    $end $start $size;
    $list = getfiles($start,$limit,$uid);
    if (!count($list)){
        return json_encode(array(
            "state" => "no match file",
            "list" => array(),
            "start" => $start,
            "total" => count($list)
        ));
    }
    $result = json_encode(array(
        "state" => "SUCCESS",
        "list" => $list,
        "start" => $start,
        "total" => count($list)
    ));
    return $result;
}
 
/**
* 获取指定文件列表
* @param int $start 开始位置
* @param int $limit 显示的条数
* @param int $uid    用户id
*/
function getfiles($start,$limit,$uid){
    Vendor('Qiniu.autoload');
    $Qiniu = C('QINIU');
    $accessKey  $Qiniu['accessKey'];
    $secretKey  $Qiniu['secretKey'];
    $bucket     $Qiniu['bucket'];
    $domain     $Qiniu['domain'];
     
    $auth new \Qiniu\Auth($accessKey$secretKey);
    $bucketMgr new \Qiniu\Storage\BucketManager($auth);
     
    // 要列取文件的公共前缀
    if($uid){
        $prefix 'test/'.$uid.'/';
    }else{
        return array();
    }
    // 上次列举返回的位置标记,作为本次列举的起点信息。
    $marker $start;
    // 本次列举的条目数
    $limit $limit $limit : 0;
    // 列举文件
    list($iterms$marker$err) = $bucketMgr->listFiles($bucket$prefix$marker$limit);
    if ($err !== null){
        return array();
    }else{
        $arr array();
        for ($i = 0; $i count($iterms); $i++){
            if(strtolower(strrchr($iterms[$i]['key'], '.')) == '.gif'){
                $arr[$i]['url'] = $domain.$iterms[$i]['key'];
            }else{
                $arr[$i]['url'] = $domain.$iterms[$i]['key'].'_600.jpg';
            }
            $arr[$i]['mtime'] = $iterms[$i]['putTime'];
        }
        return $arr;
    }
}
 
 
/**
* 上传文件
* @param 
*/
function Upload($CONFIG,$uid){
    if(!$uid){
        return json_encode(array("state" => 'error 1002'));
    }
    $base64 "upload";
    switch (htmlspecialchars($_GET['action'])) {
        case 'uploadimage':
            $config array(
                "pathFormat" => $CONFIG['imagePathFormat'],
                "maxSize" => $CONFIG['imageMaxSize'],
                "allowFiles" => $CONFIG['imageAllowFiles']
            );
            $fieldName $CONFIG['imageFieldName'];
            break;
        case 'uploadscrawl':
            $config array(
                "pathFormat" => $CONFIG['scrawlPathFormat'],
                "maxSize" => $CONFIG['scrawlMaxSize'],
                "allowFiles" => $CONFIG['scrawlAllowFiles'],
                "oriName" => "scrawl.png"
            );
            $fieldName $CONFIG['scrawlFieldName'];
            $base64 "base64";
            break;
        case 'uploadvideo':
            $config array(
                "pathFormat" => $CONFIG['videoPathFormat'],
                "maxSize" => $CONFIG['videoMaxSize'],
                "allowFiles" => $CONFIG['videoAllowFiles']
            );
            $fieldName $CONFIG['videoFieldName'];
            break;
        case 'uploadfile':
        default:
            $config array(
                "pathFormat" => $CONFIG['filePathFormat'],
                "maxSize" => $CONFIG['fileMaxSize'],
                "allowFiles" => $CONFIG['fileAllowFiles']
            );
            $fieldName $CONFIG['fileFieldName'];
            break;
    }
    $prefix 'test/'.$uid.'/';
    $key $prefix.time();
    return json_encode(UpCondition($fieldName,$config,$key));
}
 
     
/**
* 文件判断
* @param string $fileField   表单名称
* @param config $config     配置文件
* @param config $key     新文件名称
*/
function UpCondition($fileField,$config,$key){
    $file $_FILES[$fileField];
    if (!$file){
        return array("state" => '找不到上传文件');
    }
    if ($file['error']){
        return array("state" => $file['error']);
    else if (!file_exists($file['tmp_name'])) {
        return array("state" => '找不到临时文件');
    else if (!is_uploaded_file($file['tmp_name'])) {
        return array("state" => '不是上传文件');
    }
    // 文件后缀
    $ext strtolower(strrchr($file['name'], '.'));
     
    //检查文件大小是否超出限制
    if($file['file'] > $config["maxSize"]){
        return array("state" => '文件过大');
    }
    //检查是否不允许的文件格式
    if(!in_array($ext$config["allowFiles"])){
        return array("state" => '文件格式不允许');
    }
     
    $url        $key.$ext;
    $title  substr($urlstrrpos($url'/') + 1);
     
    //移动文件
    $ret = QiniuUpload($file["tmp_name"],$url);
    if($ret['status'] == 1){
        return array(
            "state" => 'SUCCESS',
            'url'       => $url,
            'title' => $title,
            'original' => $file['name'],
            'type'  => $ext,
            'size'  => $file['size'],
        );
    }else{
        return array("state" => '上传失败');
    }
}
     
     
/**
* 上传文件
* @param $filePath    要移动的文件位置
* @param $key     新文件名称
*/
function QiniuUpload($filePath,$key){
    Vendor('Qiniu.autoload');
    $Qiniu = C('QINIU');
    $accessKey  $Qiniu['accessKey'];
    $secretKey  $Qiniu['secretKey'];
    $bucket     $Qiniu['bucket'];
     
    // 初始化签权对象
    $auth new \Qiniu\Auth($accessKey$secretKey);
    $token $auth->uploadToken($bucket);
    $uploadMgr new \Qiniu\Storage\UploadManager();
     
    list($ret$err) = $uploadMgr->putFile($token$key$filePath);
     
    if($err !== null){
        $err['status'] = 0;
        return $err;
    }else{
        $ret['status'] = 1;
        return $ret;
    }
}

七牛云整合Ueditor的ThinkPHP版本的更多相关文章

  1. 初试“七牛云”--零基础运用七牛云配合UEditor实现图片的上传和浏览(.NET篇)

    (注册和建立存储空间就不介绍了,网上一把一把的资料,自己试着点点也能明白) 作为一个成熟的菜鸟,如果遇到一个新问题,第一步当然是先百度一下... 看了N个关于七牛云的使用的帖子,表示还是蒙圈的,看懂了 ...

  2. 七牛云存储官方接口PHP版本

    PHP SDKv6 此 SDK 适用于 PHP 5.1.0 及其以上版本.基于 七牛云存储官方API 构建.使用此 SDK 构建您的网络应用程序,能让您以非常便捷地方式将数据安全地存储到七牛云存储上. ...

  3. 如何利用”七牛云”在UEditor实现图片的上传和浏览

    在学习之前,我参考了朋友些的一篇关于这个功能实现的文章,非常不错.大家可以参考:http://www.cnblogs.com/John-Marnoon/p/5818528.html#3501846 里 ...

  4. 七牛整合 ueditor (拦住那头牛,七牛又如何)

    最近遇到个项目,要求所有图片都必须整合到七牛上,看了把你谈文档踩在前辈们的基础上终于把他完成了,恰巧本屌丝最近刚好有时间,本着天下屌丝是一家的原则,和小朋友们一同学习 闲话少说入正题. 第一 :下载编 ...

  5. ueditor上传图片到七牛云存储(form api,java)

    转:http://my.oschina.net/duoduo3369/blog/174655 ueditor上传图片到七牛云存储 ueditor结合七牛传图片 七牛的试炼 开发前的准备与注意事项说明 ...

  6. 在ThinkPHP框架(5.0.24)下引入Ueditor并实现向七牛云对象存储上传图片同时将图片信息保存到MySQL数据库,同时实现lazyload懒加载

    这是我花了很多天的时间才得以真正实现的一组需求. 文章后面有完整Demo的GitHub链接. 一. 需求描述 1. 应用是基于ThinkPHP5开发的: 2. 服务器环境是LNMP,PHP版本是7.2 ...

  7. python+ueditor+七牛云存储整合

    开发环境:python pyramid. 參考网址:http://developer.qiniu.com/docs/v6/sdk/python-sdk.html,http://my.oschina.n ...

  8. Ueditor结合七牛云存储上传图片、附件和图片在线管理的实现和最新更新

    最新下载地址: https://github.com/widuu/qiniu_ueditor_1.4.3 Ueditor七牛云存储版本 注意事项 老版本请查看 : https://github.com ...

  9. 【UEditor】远程上传图片到【七牛云存储】

    杂谈:最近在玩一个第三方的微信开发平台,里面的图片都是上传到[七牛云存储]的,用了一下非常的好用,支持各种语言,SDK齐全.支持全分布式系统架构以及存储技术和数据加速,于是决定将网站的图片都存储到七牛 ...

随机推荐

  1. 【转载】wondows下wget的使用

    原文地址:http://www.cnblogs.com/Randy0528/archive/2011/10/21/2219831.html 感觉要放弃windows了,,,哎,,,, 下载window ...

  2. JS日历,可获得指定日期周数及星期几

    需求来自一个朋友:编写一个简易日历.在文本框中输入要查找的日期,程序可以计算出这一天处在该年份的第几周,并且能判断出这一天到底是星期几. 应为要有交互,选择了Js来实现,也算是 结对编程 的初试吧. ...

  3. Docker 启动Centos

    docker run -d -e "container=docker" --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup --n ...

  4. CodeVS4416 FFF 团卧底的后宫

    题目描述 Description 你在某日收到了 FFF 团卧底的求助,在他某日旅游回来,他的后宫们出现了一些不可调和的矛盾,如果 FFF 团卧底把自己的宝贝分给 a 号妹子,那么 b 号妹子至少要在 ...

  5. Electron 开发环境下总是 crash

    全局安装一个 electron devtool 关掉 崩溃时选择重新打开

  6. 自然语言处理词向量模型-word2vec

    自然语言处理与深度学习: 语言模型: N-gram模型: N-Gram模型:在自然语言里有一个模型叫做n-gram,表示文字或语言中的n个连续的单词组成序列.在进行自然语言分析时,使用n-gram或者 ...

  7. PL/SQ连接oracle,L 新建表的时候, virtual那一列是什么意思

    Virtual标示该栏位是否为虚拟列. https://www.2cto.com/database/201306/216917.html

  8. 80.YCrCb - YUV - RGB之间的介绍

    一,引言 YUV(亦称YCrCb)是被欧洲电视系统所采用的一种颜色编码方法(属于PAL).YUV主要用于优化彩色视频信号的传输,使其向后兼容老式黑白电视.与RGB视频信号传输相比,它最大的优点在于只需 ...

  9. 一步一步搭建11gR2 rac+dg之安装rac出现问题解决(六)【转】

    一步一步在RHEL6.5+VMware Workstation 10上搭建 oracle 11gR2 rac + dg 之安装rac出现的问题 (六) 本文转自 一步一步搭建11gR2 rac+dg之 ...

  10. Focal Loss笔记

    论文:<Focal Loss for Dense Object Detection> Focal Loss 是何恺明设计的为了解决one-stage目标检测在训练阶段前景类和背景类极度不均 ...