📌  相关文章
📜  Laravel 函数检查图像是否存在 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:53:42.374000             🧑  作者: Mango

代码示例3
//Function will check if image exist then returned the passed image otherwise return the default image
function checkImage($path = '', $placeholder = '')
{
    if (empty($placeholder)) {
        $placeholder = 'placeholder.png';
    }

    if (!empty($path)) {
        $url = explode('storage', $path);
        $url = public_path() . '/storage' . $url[1];
        $isFile = explode('.', $url);
        if (file_exists($url) && count($isFile) > 1)
            return $path;
        else
            return asset('img/' . $placeholder);
    } else {
        return asset('img/' . $placeholder);
    }
}