webman上传图片报错

fuxu

问题描述

使用webman上传文件,获取指定文件,当指定文件不存在时候,出现报错

程序代码

public function uploadLogo(Request $request)
    {
        $file = $request->file('logo');
        if ($file && $file->isValid()) {
            $file->move(public_path().'/files/myfile.'.$file->getUploadExtension());
            return json(['code' => 0, 'msg' => 'upload success']);
        }
        return json(['code' => 1, 'msg' => 'file not found']);
    }

报错信息

TypeError: Argument 3 passed to Webman\Http\UploadFile::__construct() must be of the type string, null given, called in D:\app\wamp64\www\lhyg\vendor\workerman\webman-framework\src\Http\Request.php on line 140 and defined in D:\app\wamp64\www\lhyg\vendor\workerman\webman-framework\src\Http\UploadFile.php:48<br />
Stack trace:<br />
#0 D:\app\wamp64\www\lhyg\vendor\workerman\webman-framework\src\Http\Request.php(140): Webman\Http\UploadFile->__construct('', '', NULL, 4)<br />
#1 D:\app\wamp64\www\lhyg\vendor\workerman\webman-framework\src\Http\Request.php(119): Webman\Http\Request->parseFile(Array)<br />
#2 D:\app\wamp64\www\lhyg\app\controller\manage\Business.php(82): Webman\Http\Request->file('logo')<br />
#3 D:\app\wamp64\www\lhyg\vendor\workerman\webman-framework\src\App.php(295): app\controller\manage\Business->uploadLogo(Object(support\Request))<br />
#4 D:\app\wamp64\www\lhyg\vendor\workerman\webman-framework\src\App.php(319): Webman\App::Webman\{closure}(Object(support\Request))<br />
#5 D:\app\wamp64\www\lhyg\app\middleware\CheckManageToken.php(22): Webman\App::Webman\{closure}(Object(support\Request))<br />
#6 D:\app\wamp64\www\lhyg\vendor\workerman\webman-framework\src\App.php(311): app\middleware\CheckManageToken->process(Object(support\Request), Object(Closure))<br />
#7 D:\app\wamp64\www\lhyg\app\middleware\AccessControl.php(14): Webman\App::Webman\{closure}(Object(support\Request))<br />
#8 D:\app\wamp64\www\lhyg\vendor\workerman\webman-framework\src\App.php(311): app\middleware\AccessControl->process(Object(support\Request), Object(Closure))<br />
#9 D:\app\wamp64\www\lhyg\vendor\workerman\webman-framework\src\App.php(535): Webman\App::Webman\{closure}(Object(support\Request))<br />
#10 D:\app\wamp64\www\lhyg\vendor\workerman\webman-framework\src\App.php(129): Webman\App::findRoute(Object(Workerman\Connection\TcpConnection), '/manage/uploadL...', 'POST/manage/upl...', Object(support\Request))<br />
#11 D:\app\wamp64\www\lhyg\vendor\workerman\workerman\Connection\TcpConnection.php(638): Webman\App->onMessage(Object(Workerman\Connection\TcpConnection), Object(support\Request))<br />
#12 D:\app\wamp64\www\lhyg\vendor\workerman\workerman\Events\Select.php(311): Workerman\Connection\TcpConnection->baseRead(Resource id #155)<br />
#13 D:\app\wamp64\www\lhyg\vendor\workerman\workerman\Worker.php(2467): Workerman\Events\Select->loop()<br />
#14 D:\app\wamp64\www\lhyg\vendor\workerman\workerman\Worker.php(1453): Workerman\Worker->run()<br />
#15 D:\app\wamp64\www\lhyg\vendor\workerman\workerman\Worker.php(1396): Workerman\Worker::forkWorkersForWindows()<br />
#16 D:\app\wamp64\www\lhyg\vendor\workerman\workerman\Worker.php(560): Workerman\Worker::forkWorkers()<br />
#17 D:\app\wamp64\www\lhyg\vendor\workerman\webman-framework\src\support\App.php(124): Workerman\Worker::runAll()<br />
#18 D:\app\wamp64\www\lhyg\start.php(4): support\App::run()<br />
#19 {main}

截图报错信息里报错文件相关代码

截图

1160 2 0
2个回答

walkor 打赏

执行 composer info 看下 workerman 和 webman-framework版本是不是最新的,不是的话升级下

  • 暂无评论
fuxu

截图

  • walkor 2022-12-14

    这个问题之前修复过,你确认用workerman 4.1.4还有这个问题?

  • fuxu 2022-12-14

    我试了还是有问题,然后自己改了代码

  • walkor 2022-12-14

    之前修复没发版本,刚发了4.1.5试下

年代过于久远,无法发表回答
×
🔝