<?php
namespace app\index\controller;
use think\facade\Db;

class File
{
    public function upload()
    {
        $file = request()->file('file');
        $savename = \think\facade\Filesystem::disk('public')->putFile('', $file, 'data');

        if(in_array(strtolower(pathinfo($savename, PATHINFO_EXTENSION)), ['png','jpg','jpeg'])){
            $image  = \think\Image::open(getcwd().'/storage/'.$savename);
            $width  = 1200;
            $height = $image->height() * $width / $image->width();
            $image->thumb($width, $height)->save(getcwd().'/storage/'.$savename);
        }

        return success('上传成功', ['file'=>str_replace("\\", "/", $savename), 'name'=>$file->getOriginalName()]);
    }
}