Kindeditor join seven Qiniu upload

Source: Internet
Author: User

There are two main types of uploads for seven Qiniu:

    1. Service-side uploads

    2. Front-end upload, the front end is also divided into two ways:

      1). Redirect return, can solve the problem of Ajax cross-domain

      2). Callback returns, seven Qiniu first to the server to return data, and then seven Qiniu back to the front end, to resolve the request not to support redirection, such as small program upload

This time use is the seven Qiniu PHP SDK;

Composer require QINIU/PHP-SDK

  

Adding config.php under kindeditor/php is primarily a configuration parameter

<?phperror_reporting (0);d efined (' Root_path ') | | Define (' Root_path ', DirName (__dir__). ' /');d efined (' Qiniu_access_key ') | | Define (' Qiniu_access_key ', ');d efined (' Qiniu_secret_key ') | | Define (' Qiniu_secret_key ', ');d efined (' qiniu_test_bucket ') | | Define (' Qiniu_test_bucket ', ' Seven Qiniu Space names ');d efined (' Qiniu_bucket_domain ') | | Define (' Qiniu_bucket_domain ', ' Seven Qiniu Space URLs ');d efined (' Callback_url ') | | Define (' Callback_url ', ' Domain name/kindeditor/php/callback.php ');d efined (' Return_url ') | | Define (' Return_url ', ' Domain name/kindeditor/php/returnback.php '); require_once Root_path. " Vendor/autoload.php ";

  

Adding qiniu_token.php under kindeditor/php is mainly to generate tokens for uploading

<?phpuse qiniu\auth;require_once __dir__. " /config.php ";//construction of the Authentication object $auth = new Auth (Qiniu_access_key, qiniu_secret_key); $data = [    ' returnUrl ' + = Return_url,] if (Isset ($_request[' Is_call ')) {   $data = [      ' callbackurl ' = = Callback_url,      ' callbackbody ' = ' key= $ (key) &hash=$ (ETag) &w=$ (imageinfo.width) &h=$ (imageinfo.height) '   ];} Generate Upload Token$token = $auth->uploadtoken (qiniu_test_bucket, NULL, 3600, $data); Echo json_encode ([   ' ERROR ' = 0 ,   ' token ' = $token]);

  

Adding callback.php under kindeditor/php is primarily called back

<?php use qiniu\auth;require_once __dir__. " /config.php "; $_body = file_get_contents (' php://input '); $auth = new Auth (Qiniu_access_key, qiniu_secret_key);// Callback Contenttype$contenttype = ' application/x-www-form-urlencoded ';//callback signature information, you can verify that the callback is from seven kn $authorization = $_server[ ' Http_authorization ']; $isQiniuCallback = $auth->verifycallback ($contentType, $authorization, Callback_url, $_ if (! $isQiniuCallback) {    echo json_encode ([        ' ERROR ' = 2,        ' message ' = ' verification failed '    ]);    Die ();} $body = $_post; $qiniu _url = Qiniu_bucket_domain;if (!empty ($body [' key ')]) {    echo json_encode ([        ' ERROR ' = 0,        ' url ' = $qiniu _url. $body [' key ']    ];    Die ();} Echo Json_encode ([    ' ERROR ' = 1,    ' message ' = ' video upload error ']);

  

Adding returnback.php under kindeditor/php is primarily to redirect the receive address

<?php use qiniu\auth;require_once __dir__. " /config.php "; $upload _ret = Base64_decode ($_get[' Upload_ret ']); $upload _ret = Json_decode ($upload _ret, True); $qiniu _ url = qiniu_bucket_domain;if (!empty ($upload _ret[' key ')) {    echo json_encode ([        ' error ' + 0,        ' url ' = > $qiniu _url. $upload _ret[' key ']    );    Die ();} Echo Json_encode ([    ' ERROR ' = 1,    ' message ' = ' video upload error ']);

  

Next is the front-end change, I changed the video upload when

Kindeditor/plugins/media/media.js

Kindeditor.plugin (' Media ', function (K) {var = this, name = ' media ', lang = Self.lang (name + '. '), Allowmediaupload = K . undef (Self.allowmediaupload, true), Allowfilemanager = K.undef (Self.allowfilemanager, false), Formatuploadurl = K.undef (Self.formatuploadurl, true), Extraparams = K.undef (self.extrafileuploadparams, {' token ': '//Add token}), Filepostname = K.undef (self.filepostname, ' file '),//change file upload name Uploadjson = k.undef (Self.uploadjson, ' https://up.qbox.me ‘); Change the upload address, I use the space in the east of the east using HTTPS .... function Getqtoken () {$.getjson ('/includes/kindeditor/php/qiniu_token.php '), function (data) {K (' [name= ' token "] ', Div). val (Data.token);});}                        Get settings upload Tokengetqtoken (); if (allowmediaupload) {var Uploadbutton = K.uploadbutton ({button:k ('. Ke-upload-button '), div ) [0],fieldname:filepostname,extraparams:extraparams,url:uploadjson,//Remove add parameter afterupload:function (data) {            ... });

 

This will allow you to upload the video to the seven bull Cloud.

?

Kindeditor join seven Qiniu upload

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.