Detailed steps for THINKPHP5 to call the seven Neu Yun SDK upload files

Source: Internet
Author: User
Tags auth
detailed steps for THINKPHP5 to call the seven Neu Yun SDK upload files today, we need to upload the picture to seven cattle cloud, search on the internet for some tutorials, not all, some still lack of things, so I wrote the steps of their success, hoping to help others, this article is only suitable for THINKPHP5, other versions of Please refer to other documents, The document needs seven Neu Yun PHP-SDK, please in seven cattle cloud official download, or point my file bed download also can, address is http://filebed.rain1024.com/ 1. First create a new folder in Verdor: Qiniu 2. Extract all files from the SDK package into the Qiniu folder 3. In controller, reference classes
Vendor (' Qiniu.autoload ');
Use Qiniu\auth as Auth;
Use Qiniu\storage\bucketmanager;
Use Qiniu\storage\uploadmanager;
4. Add Configuration to config.php
' ACCESSKEY ' => ',//Your ACCESSKEY
' secretkey ' => ',//Your Secretkey ' BUCKET ' ' => '
,//uploaded space
' Domain ' => ',//space-bound domains
5. The function of the upload operation
 $file = Request ()->file (' image ');//To upload the local path of the picture $filePath = $file->getrealpath (); $ext =  PathInfo ($file->getinfo (' name '), pathinfo_extension);
Suffix//Get current controller name $controllerName = ' index '; The file name saved after uploading to seven cows $key =substr (MD5 ($file->getrealpath ()), 0, 5). Date (' Ymdhis '). RAND (0, 9999). '.' .
$ext;
Need to fill in your Access key and Secret key $accessKey = config (' AccessKey ');
$secretKey = config (' secretkey ');
To construct the $auth of the Authentication object = new Auth ($accessKey, $secretKey);
The space to upload $bucket = config (' bucket ');
$domain = config (' domainimage ');
$token = $auth->uploadtoken ($bucket);
Initializes the UploadManager object and uploads the file $uploadMgr = new UploadManager ();
Call UploadManager's Putfile method for file upload list ($ret, $err) = $uploadMgr->putfile ($token, $key, $filePath); if ($err!== null) {echo ["Err" =>1, "msg" => $err, "Data" => ""];} else {//return picture's full URL var_dump ($ret); 

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.