Kindeditor is added to qiniu cloud upload and kindeditor is uploaded to niuyun
There are two main types of qiniu cloud upload:
Server Upload
Frontend upload:
1). Redirection return can solve the problem of cross-origin ajax
2). If the callback is returned, qiniu cloud first returns data to the server, and then qiniu cloud returns the front-end, resolving the request method that does not support redirection, such as mini-program upload.
Qiniu cloud php sdk is used this time;
composer require qiniu/php-sdk
Adding config. php under Kindeditor/php is mainly a configuration parameter.
<? Phperror_reporting (0); defined ('root _ path') | define ('root _ path', dirname (_ DIR __). '/'); defined ('qiniu _ ACCESS_KEY ') | define ('qiniu _ ACCESS_KEY', '); defined ('qiniu _ SECRET_KEY ') | define ('qiniu _ SECRET_KEY ', ''); defined ('qiniu _ TEST_BUCKET') | define ('qiniu _ TEST_BUCKET ', 'qiniu cloud space name'); defined ('qiniu _ BUCKET_DOMAIN ') | define ('qiniu _ BUCKET_DOMAIN', 'qiniu cloud space website '); defined ('callback _ url') | define ('callback _ url', 'domain name/kindeditor/php/CALLBACK. php '); defined ('Return _ url') | define ('Return _ url', 'domain name/kindeditor/php/returnBack. php '); require_once ROOT_PATH. "vendor/autoload. php ";
Add qiniu_token.php under Kindeditor/php to generate the token for upload.
<? Phpuse Qiniu \ Auth; require_once _ DIR __. "/config. php "; // construct 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]);
Add callBack. php under Kindeditor/php mainly for callBack
<? Php use Qiniu \ Auth; require_once _ DIR __. "/config. php "; $ _ body = file_get_contents ('php: // input'); $ auth = new Auth (QINIU_ACCESS_KEY, QINIU_SECRET_KEY ); // The callback contentType $ contentType = 'application/x-www-form-urlencoded'; // The callback signature information, you can verify whether the callback is from qiniu $ authorization =$ _ SERVER ['HTTP _ authorization']; $ isQiniuCallback = $ auth-> verifyCallback ($ contentType, $ AUTHORIZATION, CALLBACK_URL, $ _ body); 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 ']);
Add returnBack. php In Kindeditor/php to redirect the Receiving 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. When I change it, the video will be uploaded.
Kindeditor/plugins/media. js
KindEditor. plugin ('Media ', function (K) {var self = 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 the file Upload name uploadJson = K. undef (self. uploadJson, 'https: // up. qbox. me '); // change the upload address. When I use the space in the East China region, I Use https .... function getQToken () {$. getJSON ('/includes/kindeditor/php/qiniu_token.php', function (data) {K ('[name = "token"]', div ). val (data. token) ;}) ;}// get the settings to upload tokengetQToken (); if (allowMediaUpload) {var uploadbutton = K. uploadbutton ({button: K ('. ke-upload-button ', div) [0], fieldName: filePostName, extraParams: extraParams, url: uploadJson, // remove the Add parameter afterUpload: function (data) {...});
You can upload the video to qiniu cloud.