OSS Object storage is a secure, low-cost, high-reliability cloud storage Service, this paper takes the image upload and seven Qiniu storage as an example to realize the OSS storage function.
PHP Seven Cow cloud installation
Installing with composer
#安装 Composer Curl-ss Https://getcomposer.org/installer | php# use Composer to get the latest version of Qiniu SDK PHP Composer.phar require qiniu/php-sdk# code require Composer generated autoloader<?php Require ' vendor/autoload.php ';
PHP uses the seven KN SDK
<?php require_once './vendor/autoload.php '; The introduction of the authentication class use Qiniu\auth; Introduction of upload class use Qiniu\storage\uploadmanager; Need to fill in your access key and Secret key $accessKey = ' access key '; $secretKey = ' Secret Key '; Building the Authentication object $auth = new Auth ($accessKey, $secretKey); The space to upload $bucket = ' test '; Generate upload Token $token = $auth->uploadtoken ($bucket); Initializes the UploadManager object and uploads the file $uploadMgr = new UploadManager (); if ($_files) {$key = $_files["File" ["Name"]; Call UploadManager's Putfile method to upload the file list ($ret, $err) = $uploadMgr->putfile ($token, $key, $_files["file"] [TM P_name "]); if ($err!== null) {var_dump ($err); } else {$data [' code '] = 1; $data [' message '] = ' success '; $data [' img_url '] = ' http://7xplx9.com1.z0.glb.clouddn.com/'. $ret [' key ']; $data [' markdown_img '] = ' [Off-site image] (2)] '; Markdown Picture loading format exit (Json_encode ($data)); } }
HTML upload page, using
Use Dropzone to drag and drop upload plugins
<! DOCTYPE html>