Thinkphp using seven cow cloud upload

Source: Internet
Author: User

Store files with seven Qiniu private spaces

The first step is to register the seven Cow cloud, create space, and set the space as private

Something to write down:

Ak,sk,bucket

Second Step configuration thinkphp

Add in config.php

' Upload_siteimg_qiniu ' =>array (' maxSize ' =>5*1024*1024,//file size ' rootpath ' = './', ' Savename ' =>array (' Uniqid ', '), ' driver ' = ' qiniu ', ' Driverconfig ' =>array (' secrectkey ' = ' < here fill seven kn sk> ', ' accessKey ' = ') < here fill seven kn 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);

  

Copy Code


The $info you get when uploading a file is this.

Array (1) {["Photo"]=>array (Ten) {["Name"]=>["type"]=>["size"]=>["key"]=> "[" ext "]=>[" SHA1 "]=> ["Savename"]=>["Savepath"]=>["url"]=>}}

  

Copy Code


Fourth step, calculate download voucher

Common directory function.php Add method

Functionqiniu_encode ($STR)//urlsafebase64encode{$find =array (' + ', '/'); $replace =array ('-', ' _ '); returnstr_replace ($find, $replace, Base64_encode ($STR));} Functionqiniu_sign ($url) {//$info inside of 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 resource

Reference

Http://document.thinkphp.cn/manual_3_2.html#upload

Http://developer.qiniu.com/docs/v6/api/reference/security/download-token.html

Thinkphp using seven cow cloud 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.