我有这个来获取用户图像,它是为 jpg 硬编码的,但有些用户上传了 png,有些用户上传了 gif,我如何使它适用于所有格式?
function get_avatar($image, $user_id, $account)
{
$imgurl =$_SERVER["REQUEST_SCHEME"] . "://" . $_SERVER["HTTP_HOST"] . "/files/pictures/picture-" . ($user_id) . ".jpg";
if (!is_imgurl_good($imgurl)) {
$imgurl =$_SERVER["REQUEST_SCHEME"] . "://" . $_SERVER["HTTP_HOST"] . "/sites/all/themes/simple_custom/user.png";
}
return $imgurl;
}
function is_imgurl_good($imgurl) {
if (@getimagesize($imgurl))
return true;//Check that if this returns false the previous function works
//return false; //Comment out the first line and uncomment this one to show the reverse case.
}
森林海
慕桂英546537