umeditor图片上传至七牛

确定图片上传实例化类的路径,查看umeditor/php/index.php

header("Content-Type:text/html;charset=utf-8");
error_reporting(E_ERROR | E_WARNING);
date_default_timezone_set("Asia/chongqing");
include "uploaderController.php"; //上传配置
$config = array(
    "savePath" => "upload/", //存储文件夹
    "maxSize" => 1000, //允许的文件最大尺寸,单位KB
    "allowFiles" => array(".gif", ".png", ".jpg", ".jpeg", ".bmp") //允许的文件格式
); //实例化图片上传类
$up = new uploaderController("upfile", $config);
$type = $_REQUEST['type']; $callback = $_GET['callback'];
$info = $up->getFileInfo();
/**
* 返回数据
*/
if ($callback) {
    echo '<script>' . $callback . '(' . json_encode($info) . ')</script>';
} else {
    echo json_encode($info);
}

修改uploderController.php 上传类 upfile()

// $folder = $this->getFolder();
//不上传到本地
// if ( $folder === false ) { // $this->stateInfo = $this->getStateInfo( "DIR_ERROR" );
//     return;
// }
// $this->fullName = $folder . '/' . $this->getName();
// if ( $this->stateInfo == $this->stateMap[ 0 ] ) {
//     if ( !move_uploaded_file( $file[ "tmp_name" ] , $this->fullName ) ) {
//         $this->stateInfo = $this->getStateInfo( "MOVE" );
//     }
// }
//使用七牛上传
$result=$this->updateQiniu($file[ "tmp_name" ]);
$this->fullName='http://xxxxxxx.bkt.clouddn.com/'.$result['hash'];

实现updateQiniu() 方法

private function updateQiniu($tmp_name){
    include '../../../../../vendor/qiniu/php-sdk/autoload.php'; //十分重要
    $accessKey = 'xxxxxxxxx';
    $secretKey = 'xxxxxxxxx';
    $auth = new Auth($accessKey, $secretKey);
    $bucket = 'ulala-test';
    $token = $auth->uploadToken($bucket);
    // 要上传文件的本地路径
    $filePath =$tmp_name;
    $uploadMgr =new UploadManager();
    $key=null;
    list($ret, $err) = $uploadMgr->putFile($token,$key, $filePath);
    if ($err !== null) {
        return $err;
    } else {
        //成功的返回数组 hash 和key
        return $ret;
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,323评论 19 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,149评论 25 709
  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 11,713评论 0 17
  • for循环的语法格式 for(初始化;条件;语句块1){语句块2} for(A;B;C){ D }//执行顺序为A...
    归隐3中阅读 2,849评论 0 0
  • 1.透明模式:Performance L4 + DNAT 原理:这种类型的Virtual server.F5按照纯...
    死海死阅读 22,589评论 0 3