Correct PHP way to check if external image exists?

后端 未结 9 1321
清歌不尽
清歌不尽 2021-02-04 08:49

I know that there are at least 10 the same questions with answers but none of them seems to work for me flawlessly. I\'m trying to check if internal or external image exists (is

9条回答
  •  时光取名叫无心
    2021-02-04 09:52

    You can use the PEAR/HTTP_Request2 Package for this. You can find it here

    Here comes an example. The Example expects that you have installed or downloaded the HTTP_Request2 package properly. It uses the old style socket adapter, not curl.

     new HTTP_Request2_Adapter_Socket())
    );
    
    switch($request->send()->getResponseCode()) {
    
        case 404 : 
            echo 'not found';
            break;
    
        case 200 :
            echo 'found';
            break;
    
        default :
            echo 'needs further attention';
    
    }
    

提交回复
热议问题