ThinkPHP6.1 Filesystem 替换方案
在ThinkPHP6.1 发布以后,移除·Filesystem
类库,文件上传无法使用,但是think\File
依旧有进行保留,可以使用think\File
代替进行文件操作,文件上传代码如下
<?phpnamespace 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('文件地址');得到文件对象* /}
不足之处,请多指教