Thinkphp using seven cattle cloud upload (from thinkphp official website)

Source: Internet
Author: User
Tags sha1
Use seven Neu Yun private space to store files
The first step, register seven Cow cloud, create the space, make the space private
Something to write down:
Ak,sk,bucket
Second Step configuration thinkphp
Add ' Upload_siteimg_qiniu '  => array  in config.php (                    ' MaxSize '  => 5 * 1024  * 1024,//File Size                   ' RootPath '  =>  './',                   ' Savename '  => array  (' uniqid ',  '),                   ' driver '  =>  ' Qiniu ',                  ' Driverconfig '  => array  (                          ' Secrectkey '  =>  ' < fill in seven beef SK > ',                            ' AccessKey '  =>  ' < fill out here seven cows ak> ',                           ' Domain '  =>  ' < space name >.qiniudn.com ',                           ' bucket '  =>   ' < space name > ',               ' copy code step three, upload the file.
Controller $setting =c (' Upload_siteimg_qiniu '); $Upload = new \think\upload ($setting); $info = $Upload->upload ($_files);     The $info that is obtained after copying the code upload file is such array (1) {[PHOTO] => Array {[' name '] => [' type '] => [' Size '] =>     ["Key"] => ["ext"] => ["SHA1"] => ["Savename"] => ["Savepath"] => ["url"] => Copy Code step Fourth, calculate the download voucher
Common directory function.php Add method Function qiniu_encode ($str)  // urlsafebase64encode {      $find  = array (' + ',  '/');      $replace  = array ('-',  ' _ ');     return str_replace ($find,  $replace,  base64_encode ($STR)); Function qiniu_sign ($url)  {//$info url      $setting  = C  (  ' Upload_siteimg_qiniu '  );      $duetime  = now_time + 86400;//Download voucher valid time     $ downloadurl =  $url  .  ' e= '  .  $duetime;      $Sign  = hash_hmac  (  ' SHA1 ',  $DownloadUrl,  $setting   ["Driverconfig"] ["Secrectkey"], true );      $EncodedSign  = Qiniu_Encode  (  $Sign  );      $Token  =  $setting  ["Driverconfig"] ["AccessKey"] .  ': '  .  $EncodedSign;      $RealDownloadUrl  =  $DownloadUrl  .  ' &token= '  .  $Token ;     return  $RealDownloadUrl; Copy code $REALDOWNLOADURL to download the available URLs for the corresponding private resources
Reference
Http://document.thinkphp.cn/manual_3_2.html#upload
Http://developer.qiniu.com/docs/v6/api/reference/security/download-token.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.