Correct PHP way to check if external image exists?

后端 未结 9 1302
清歌不尽
清歌不尽 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:47

    This code is actually to check file... But, it does works for images!

    $url = "http://www.myfico.com/Images/sample_overlay.gif";
    $header_response = get_headers($url, 1);
    if ( strpos( $header_response[0], "404" ) !== false )
    {
       // FILE DOES NOT EXIST
    } 
    else 
    {
       // FILE EXISTS!!
    }
    

提交回复
热议问题