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);