Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

Laravel function to check if image exist or not

//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);
    }
}
Source by www.itsolutionstuff.com #
 
PREVIOUS NEXT
Tagged: #Laravel #function #check #image #exist
ADD COMMENT
Topic
Name
2+4 =