当前位置:网站首页>PHP: seven cattle cloud upload file
PHP: seven cattle cloud upload file
2022-06-12 10:20:00 【Qu Shuai 369】
install sdk
composer require qiniu/php-sdkCode
<?php
namespace app\api\controller;
use Qiniu\Auth;
use Qiniu\Storage\UploadManager;
class Qn
{
static private $accessKey = "CqfperBEHyoU8u7x5uvyjb6r2XCYaz**********";
static private $secretKey = "lVMaQWHoIDlOLN1AGOM3B0GKG30NQa**********";
static private $bucket = "qncdn369";
static private $http_host = "";
// After obtaining the upload voucher, the form is uploaded
public function token()
{
$auth = new Auth(self::$accessKey, self::$secretKey);
$token = $auth->uploadToken(self::$bucket);
return json(['status' => 1, 'msg' => ' success ', 'data' => $token]);
}
// Server direct transmission
public function up()
{
if(empty($_FILES['file']['tmp_name'])) return json(['status' => 0, 'msg' => ' Please upload the file ', 'data' => '']);
// You need to fill in your Access Key and Secret Key
$accessKey = self::$accessKey;
$secretKey = self::$secretKey;
$bucket = self::$bucket;
// Build authentication object
$auth = new Auth($accessKey, $secretKey);
// Generate upload Token
$token = $auth->uploadToken($bucket);
// Local path to upload file
$filePath = $_FILES['file']['tmp_name'];
// File name saved after uploading to storage
$key = randString(16);
// initialization UploadManager Object and upload the file .
$uploadMgr = new UploadManager();
// call UploadManager Of putFile Method to upload the file .
list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
if ($err !== null) {
return json(['status' => 0, 'msg' => ' Upload failed ', 'data' => '']);
} else {
return json(['status' => 1, 'msg' => ' Upload successful ', 'data' => ['url'=>self::$http_host.$key]]);
}
}
}
边栏推荐
- spark_ sql
- IoT简介
- 1268_FreeRTOS任务上下文切换的实现
- 用于图像处理的高性能计算框架
- Auto. JS debugging: use the network mode of lightning simulator for debugging
- Yarn scheduling
- Halcon combined with C # to detect surface defects -- affine transformation (III)
- Wechat payment, wechat refund, Alibaba payment
- Antique mfc/gdi+ Frame LCD display control
- Detailed explanation and use of redis data types: key and string types
猜你喜欢

GNU EFI development environment settings

Research on autojs wechat: the control IP in wechat on different versions of wechat or simulators is different.

ASP. Net core permission system practice (zero)
![[926. flip the string to monotonic increment]](/img/fa/1838405693aa0998694d4895a611c2.png)
[926. flip the string to monotonic increment]

一文读懂Dfinity生态中的首个NFT平台:IMPOSSIBLE THINGS

Tp6 debugging (trace)

MySQL 4 Database table storage structure & tablespace
![Data processing and visualization of machine learning [iris data classification | feature attribute comparison]](/img/a3/1d181b9dd5268e13cc276a78862d1f.png)
Data processing and visualization of machine learning [iris data classification | feature attribute comparison]

1268_FreeRTOS任务上下文切换的实现

学生管理系统
随机推荐
Periodic pains of cross-border e-commerce? Papaya mobile power as an independent station enabler
Auto. JS learning note 4: after autojs is packaged, most Huawei and other big brand mobile phones cannot be installed? This problem can be solved by using the simulator to remotely sign and package in
Antique mfc/gdi+ Frame LCD display control
2022淘宝618超级喵运会玩法来了 超级喵运会有哪些攻略方法
2022京东618预售定金怎么退?京东618定金能退吗?
ASP.NET Core权限系统实战(零)
Yarn scheduling
postgresql 使用存储过程,拼接多张表,查询数据
[CEGUI] concept introduction
Circuitbreaker fuse of resilience4j - circuitbreakerevent event
学生管理系统
Pagoda chevereto1.6.2 the latest version of stepping on the pit tutorial in Chinese
Download Notepad++
Remote link software xshell and xftp download address
容器江湖的爱恨情仇
MYSQL的最左匹配原则的原理讲解
Chromebook system without anti-virus software
【926. 将字符串翻转到单调递增】
一文读懂Dfinity生态中的首个NFT平台:IMPOSSIBLE THINGS
验收标准到底是不是测试用例?