分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

tp5 用 oss文件上传

发布时间:2023-09-06 01:37责任编辑:熊小新关键词:文件上传

首先用 composer require aliyuncs/oss-sdk-php安装插件

然后在入口文件加入

require_once __DIR__ .‘/../vendor/aliyuncs/oss-sdk-php/autoload.php‘;

在文件上传类 File.php中添加一个方法

必须引入这俩文件

use OSS\OssClient;
use OSS\Core\OssException;
Public function moveOss($accessKeyId,$accessKeySecret,$endpoint,$bucket,$object,$content)
{
try {
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
$res= $ossClient->putObject($bucket, $object, $content);
} catch (OssException $e) {
print $e->getMessage();
}
return $res[‘info‘][‘url‘];
}

控制器

class Img extends Controller
{
public function index()
{
return view(‘add‘);
}
public function insert()
{
$file = request()->file(‘img‘);
$img=$file->getInfo();
$object="images/".$img[‘name‘];
$content=file_get_contents($img[‘tmp_name‘]);
$info=$file->moveOss(‘LTAIYKANPIug9wAi‘,‘ZSJPmzWXdhKTss5M51UzgeOiXN3ZXD‘,
???????????????????????‘http://oss-cn-beijing.aliyuncs.com‘,‘yan0208‘,$object,$content);
echo $info;
}
}
composer require aliyuncs/oss-sdk-php

tp5 用 oss文件上传

原文地址:https://www.cnblogs.com/yanyan0208/p/8297409.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved