1. Step 1 download qiniuyun SDK with Composer

Run in the project directory

composer require qiniu/php-sdk
Copy the code

2. Carry out the configuration required by Qiuniuyun (methods and configurations can be packaged by themselves)

use Qiniu\Auth; // Use Qiniu\Storage\UploadManager; Public function qiniuyunUploading() {// Set $ak=' qik-qlg1r12lyybecccirl_7jeaexmy_ytsrgd2q '; // Set $ak=' qlG1R12lyyBECcCIRL_7JEAeXmY_ytsRgD2q'; AccessKey $sk=' iudzwxjTN-hctpkkqvkbsm1SY1-1UU-bmnkadca '; $bucket=' XCMZBC '; Seven NiuYun bucket name / / / / get image information $file = \ request () - > file (' the name of the upload pictures'); $filePath=$file->getRealPath(); $ext=pathinfo($file->getInfo('name'), PATHINFO_EXTENSION); $newName= MD5 (date(time()).rand(10000000,99999999)). '.'.$ext; $auth=new auth ($ak,$sk); $token=$auth->uploadToken($bucket); $uploadMgr=new UploadManager(); List ($ret,$err)=$uploadMgr->putFile($token,$newName,$filePath); If ($err! == null){ return $err; die(); } return $ret; }Copy the code

Tip: If the applet does not load the image correctly

Concatenate http:// before accessing the domain name