ThinkPHP6.1 移除了Filesystem,有效的替换方法

chenvle 2022-11-07 PM 1193℃ 0条

V6.1.0(2022年10月26日)
移除核心对think-filesystem库的依赖

在ThinkPHP6.1 发布以后,移除·Filesystem类库,文件上传无法使用,但是thinkFile 依旧有进行保留,可以使用thinkFile 代替进行文件操作,文件上传代码如下

方法一:自己封装

common.php 通用方法

if (!function_exists('fileUpdate')) {
    function fileUpdate ($file,$save_url = './upload/')
    {
        $fileInfo = pathinfo($file);
        $extension = strtolower($file->getOriginalExtension());
        $filePath = $fileInfo['dirname'] . '/' . $fileInfo['basename'];
        $file = new \think\File($filePath);
        $savePath = $save_url.date('Ymd').'/';
        $file->move($savePath, $file->md5() . '.' . $extension);
        return $savePath . $file->md5() . '.' . $extension;
    }
}

index.php 控制器

<?php

namespace app\controller;
use app\BaseController;

class index extends BaseController
{
    public function index(){
        $file     = request()->file('file');
        $url      = fileUpdate($file);
    }
}

方法二: 重新安装think-filesystem

composer require topthink/think-filesystem

非特殊说明,本博所有文章均为博主原创。

评论啦~