thinkphp6上传视频
文章描述:
thinkphp6表单上传视频
配置filesystem.php
<?php
// 磁盘配置
return [
// 默认磁盘
'default' => env('filesystem.driver', 'local'),
// 磁盘列表
'disks' => [
'local' => [
'type' => 'local',
'root' => app()->getRuntimePath() . 'storage',
],
'public' => [
// 磁盘类型
'type' => 'local',
// 磁盘路径
'root' => app()->getRootPath() . 'public/storage',
// 磁盘路径对应的外部URL路径
'url' => '/storage',
// 可见性
'visibility' => 'public',
],
// 更多的磁盘配置信息
],
];
表单
<form action="{:url('upload')}" method="post" enctype="multipart/form-data">
<input type="file" name="file" accept="video/*">
<button type="submit">上传视频</button>
</form>
上传方法
<?php
namespace app\controller;
use think\facade\View;
use think\Request;
use think\facade\Filesystem;
class Index
{
// 表单 http://localhost:9526/Index/index
public function index()
{
return View::fetch('index');
}
//
public function upload(Request $request)
{
$file = request()->file('file');
$file_name = Filesystem::disk('public')
->putFile('file', $file, '');
if($file_name) return success(['videoUrl'=>$file_name],'上传视频成功',200);
return success([],'上传视频失败',200);
}
}
上传后地址路径public/storage/file/20250423
发布时间:2025/04/23
发表评论