示例#1
0
function isSmallPicture($url, $size = false)
{
    if (!$size) {
        $size = SMALL_PICTURE_LIMIT;
    }
    $client = new Guzzle\Http\Client($url, ['request.options' => ['timeout' => 2, 'connect_timeout' => 2]]);
    $request = $client->head('');
    try {
        $response = $request->send();
        $length = $response->getHeader('content-length');
        if ($length) {
            $length = (int) $length->toArray()[0];
            $type = (string) $response->getHeader('content-type');
            $typearr = explode('/', $type);
            return $typearr[0] == 'image' && $length <= $size && $length >= 10000;
        }
        return false;
    } catch (\Exception $e) {
        return false;
    }
}