DiscuzQ在Linux下后台全局设置无法上传图片问题解决


admin-logo-x2 (1).png

Linux下后台全局配置无法上传图片,可以修改项目下的文件

app\Api\Controller\Settings\UploadLogoController.php

将 data 方法修改成如下:

    protected function data(ServerRequestInterface $request, Document $document) {
        $actor = $request->getAttribute('actor');
        $this->assertCan($actor, 'setting.site');
        UrlGenerator::setRequest($request);
        $type = Arr::get($request->getParsedBody(), 'type', 'logo');
        $file = Arr::get($request->getUploadedFiles(), 'logo');
        $document_root = Arr::get($request->getServerParams(), 'DOCUMENT_ROOT');
        $verifyFile = new UploadedFile(
                $file->getStream()->getMetadata('uri'),
                $file->getClientFilename(),
                $file->getClientMediaType(),
                $file->getError(),
                true
        );
        $mimes = [
            'watermark_image' => 'mimes:png',
            'favicon' => 'mimes:jpeg,jpg,png,bmp,gif,ico,svg',
        ];
        $this->validator->make(
                ['type' => $type, 'logo' => $verifyFile],
                [
                    'type' => [Rule::in($this->allowTypes)],
                    'logo' => [
                        'required',
                        $mimes[$type] ?? 'mimes:jpeg,jpg,png,bmp,gif',
                        'max:5120'
                    ]
                ]
        )->validate();
        $fileName = $type . '.' . $verifyFile->getClientOriginalExtension();
        try {
            move_uploaded_file($file->getStream()->getMetadata('uri'), $document_root . DIRECTORY_SEPARATOR . "storage" . DIRECTORY_SEPARATOR . $fileName);
        } catch (Exception $e) {
            throw new $e;
        }
        $this->settings->set($type, $fileName, $type === 'watermark_image' ? 'watermark' : 'default');
        return [
            'key' => 'logo',
            'value' => $this->url->to('/storage/' . $fileName) . '?' . Carbon::now()->timestamp,
            'tag' => 'default'
        ];
    }

保存后重试

声明:版权所有,违者必究|如未注明,均为原创|本网站采用 BY-NC-SA协议进行授权

转载:转载请注明原文链接 - DiscuzQ在Linux下后台全局设置无法上传图片问题解决

点击排行