1-安裝七牛云官方SDK
composer require qiniu/php-sdk -vvv
2-七牛云配置
~~~
1----config文件
//七牛云配置
'qiniu' => [
'accessKey' => '.......................................',
'secretKey' => '.......................................',
'domain' => '.............................',//域名地址
'bucket' => '......',//空間名稱
'zone'=> 'south_china'//區域
],
~~~
3- 對應的控制器
~~~
use Qiniu\Auth;
require 'vendor/qiniu/php-sdk/autoload.php'; //引入自動加載類
use Qiniu\Storage\UploadManager; //實例化上傳類
public function add(){
$file = request()->file('img');
// 要上傳圖片的本地路徑
$filePath = $file->getRealPath();
$ext = pathinfo($file->getInfo('name'), PATHINFO_EXTENSION); //后綴
// 上傳到七牛后保存的文件名
$key =substr(md5($file->getRealPath()) , 0, 5). date('YmdHis') . rand(0, 9999) . '.' . $ext;
// 需要填寫你的 Access Key 和 Secret Key
// 構建鑒權對象
$accessKey =config("qiniu")["accessKey"];
$secretKey =config("qiniu")["secretKey"];
$auth=new Auth($accessKey,$secretKey);
// 要上傳的空間
$bucket =config("qiniu")["bucket"];
//域名
$domain=config("qiniu")["domain"];
$token = $auth->uploadToken($bucket);
// 初始化 UploadManager 對象并進行文件的上傳
$uploadMgr = new UploadManager();
// 調用 UploadManager 的 putFile 方法進行文件的上傳
list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
if ($err !== null) {
return ["err"=>1,"msg"=>$err,"data"=>""];
} else {
//返回圖片的完整URL
$imgPath=$domain.'/'.$key;
//賦值
$data["thumb_url"] = $imgPath;
$data = Db::name('top_bar')->insert($data);
$this->redirect("/admin/topbar/index");
}
}
~~~
- tp5圖片上傳
- 文件上傳到七牛云
- 上傳到阿里云
- 富文本編輯器
- phpexcel和spreadsheet
- phpexcel導出
- phpexcel導入
- spreadsheet
- tp5_api接口
- 跨域請求
- JWT
- 圖片和視頻上傳接口
- 驗證碼
- tp5小程序登錄
- tp5小程序支付
- tp5基礎架構
- 驗證層
- 模型層Model
- 控制器構找
- tp5.0支付寶
- 海報二維碼
- 輪播圖
- echarts柱狀圖
- layui的圖片彈窗
- p標簽顯示指定行數(全部)
- jquery和layerdate調用日期
- ajax發送文件和圖片的坑啊
- JS日期點擊上一天和下一天
- 百度分享js
- POST請求
- 商品數據表
- tp5.0支付寶最全
- tp5路由的坑
- 二維數組排序
- tp5模型分組group錯誤
- 二維變一維數組
- 無限樹形結構
- json對象轉數組
- 模型關聯查詢
- tp5的模型獲取器和字段設定
- 經緯度獲取距離排序