uploadToken($bucket); // 上传到存储后保存的文件名 $filename = pathinfo($filePath, PATHINFO_FILENAME); $key = getenv('APP_NAME') .'/' . date('Ymd') . '/' . $filename . '.' . pathinfo($filePath, PATHINFO_EXTENSION); // 初始化 UploadManager 对象并进行文件的上传。 $uploadMgr = new UploadManager(); // 调用 UploadManager 的 putFile 方法进行文件的上传。 list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath, null, 'application/octet-stream', true, null, 'v2'); if ($err !== null) { throw new Exception($err->getResponse()->error); } $qiniu_url = getenv('QI_NIU_URL') . '/' . $ret['key']; return [ 'code' => ResponseCode::SUCCESS, 'data' => $qiniu_url, ]; }catch (Exception $e){ return [ 'code' => ResponseCode::FAIL, 'msg' => $e->getMessage() ]; } } }