ThinkPHP6.1 Filesystem替换方案
方案一
重新composer 安装
composer require topthink/think-filesystem
方案二
改代码
<?php
namespace app\index\controller;
use app\BaseController;
use think\File;
class Index extends BaseController
{
public function Upload($file)
{
// 获取文件基本信息
$fileInfo = pathinfo($file);
// 获取文件后缀
$extension = strtolower($file->getOriginalExtension());
// 获取文件地址和名称
$filePath = $fileInfo['dirname'] . '/' . $fileInfo['basename'];
// 文件地址转文件类
$file = new File($filePath);
// 文件转存目录(按自己喜好定义就行)
$savePath = root_path() . 'public/uploads/'.date('Y-m-d').'/';
// 新的文件名(按自己喜好生成就行)
$fileName = $file->md5() . '.' . $extension;
// 转移临时文件到指定目录
$file->move($filePatch, $savePath.$fileName);
// 按照业务逻辑继续编写
.......
}
/**
* 也可以使用 $file = new File('文件地址');得到文件对象
* /
}
版权声明:
作者:超级管理员
链接:
https://blog.apecloud.ltd/article/detail.html?id=ThinkPHP6-Filesystem
来源:猿码云个人技术站
文章版权归作者所有,未经允许请勿转载。
THE END
二维码
打赏


共有0条评论