阿里云oss 简单上传
生活随笔
收集整理的這篇文章主要介紹了
阿里云oss 简单上传
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、創建Bucket "桶名"
?
2、獲取密鑰
?
3、?在框架中引用阿里云插件??PHP - 對象存儲 OSS - 阿里云
composer require aliyuncs/oss-sdk-php舉個簡單例子:
創建一個簡單表單
<form action="{{route('ali.oss')}}" method="post" enctype="multipart/form-data">@csrf文件:<input type="file" name="image"><br><button type="submit">提交</button> </form>方法
use OSS\OssClient; use OSS\Core\OssException; public function alioss(Request $request){#獲取上傳文件本機信息$image=$_FILES;#當前文件路徑$imagePath=$image['image']['tmp_name'];#當前名$imageName=$image['image']['name'];#取后綴$suffix=pathinfo($imageName)['extension'];#重命名$newImage=md5(rand(1111,99999).uniqid()).'.'.$suffix;#阿里云上傳// 阿里云賬號AccessKey擁有所有API的訪問權限,風險很高。強烈建議您創建并使用RAM用戶進行API訪問或日常運維,請登錄RAM控制臺創建RAM用戶。$accessKeyId = "";$accessKeySecret = "";// yourEndpoint填寫Bucket所在地域對應的Endpoint。以華東1(杭州)為例,Endpoint填寫為https://oss-cn-hangzhou.aliyuncs.com。$endpoint = "https://oss-cn-hangzhou.aliyuncs.com";// 填寫Bucket名稱,例如examplebucket。$bucket= "桶名";try{$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);$ossClient->uploadFile($bucket, $newImage, $imagePath);} catch(OssException $e) {printf(__FUNCTION__ . ": FAILED\n");printf($e->getMessage() . "\n");return;}echo "上傳成功";}這個時候一定要運行一下!!!!!!
回報一個類似于這個的錯誤 找不到證書
curl: (60) SSL certificate problem: unable to get local issuer certificate 錯誤那么不要急不要慌 !!!! 解決方案如下:
a、在下面鏈接下在下載一個ca-bundle.crt 放到php 文件?ssl文件下
GitHub - bagder/ca-bundle: The Mozilla CA bundle extracted and converted to PEM. This repository functions as a backup to the automated service on the curl web site.b、在php.ini加入
以我的為例,每個人根據自己情況
curl.cainfo="D:\phpstudy_pro\Extensions\php\php7.3.4nts\extras\ssl/ca-bundle.crt"c、重啟服務器
這樣 一個簡單的阿里云oss上傳就完成了
總結
以上是生活随笔為你收集整理的阿里云oss 简单上传的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何做相册_手机里的照片太多,不得已只能
- 下一篇: java 线程 状态 图_Java提高—