PHP drag and drop upload image to seven cow cloud

Source: Internet
Author: User
Tags autoload
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>

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.