webman-admin 图片路径问题

yygy125

问题描述

在webman-admin后台上传的图片地址格式为 http://0.0.0.0:8787/app/admin/upload/files/20260503/69f70f593299.jpeg

但在API需要返回给客户端用,不想显示/app/admin ,想要转成类似 http://0.0.0.0:8787/upload/files/20260503/69f70f593299.jpeg 要在哪里配置?

114 1 0
1个回答

mass_wm

plugin\admin\app\controller\UploadController.php
找到上传类中的部分代码如下:

        $relative_path = $relative_dir . '/' . bin2hex(pack('Nn',time(), random_int(1, 65535))) . ".$ext";
        $full_path = $base_dir . $relative_path;
        $file_size = $file->getSize();
        $file_name = $file->getUploadName();
        $mime_type = $file->getUploadMimeType();
        $file->move($full_path);
        $image_with = $image_height = 0;
        if ($img_info = getimagesize($full_path)) {
            [$image_with, $image_height] = $img_info;
            $mime_type = $img_info['mime'];
        }
        return [
            'url'     => "/app/admin/$relative_path", #-----------这里可以尝试下修改
            'name'     => $file_name,
            'realpath' => $full_path,
            'size'     => $file_size,
            'mime_type' => $mime_type,
            'image_with' => $image_with,
            'image_height' => $image_height,
            'ext' => $ext,
        ];
  • mass_wm 2026-05-07

    这个方法在类中被调用了几次,酌情修改

  • 尘封 2026-05-07

    nginx里转发下

🔝