0

嗨,我正在使用 unisharp laravel-filemanager 让用户上传他们的产品照片

图片上传的时候

此地址将保存在数据库中

/photos/44/606074649c651.jpg

我可以使用它

{{asset('storage/'.$product->cover_img)}}

和缩略图保存在这个地址

/photos/44/thumbs/606074649c651.jpg

如何获取缩略图的地址以及如何在刀片中使用它?

这是答案

@php($lastSlash = strrpos($product->cover_img,"/"))

src="{{asset('storage/'.substr_replace($product->cover_img, 'thumbs/', $lastSlash+1) .'' .substr($product->cover_img ,$lastSlash+1))}}"
4

1 回答 1

0

你可以使用这样的函数:

function getThumbs($url=""){
    $base = basename($url);
    if (strpos($url, 'https://') !== false or strpos($url, 'http://') !== false) {
        return str_replace($base, "thumbs/".$base, $url);
    }else{
        $preUrl = "storage/";
        $beforeBase = str_replace($base, "",$url);
        return $preUrl.$beforeBase.'thumbs/'.$base;
    }
}

并在您的刀片使用中:

<img src="{{ getThumbs($product->cover_img) }}" .../>
于 2021-07-01T04:46:07.260 回答