Correct PHP way to check if external image exists?

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

    If you're using PHP >=5.0.0 you can pass an additional parameter into fopen to specify context options for HTTP, among them whether to ignore failure status codes.

    $contextOptions = array( 'http' => array('ignore_errors' => true));
    
    $context = stream_context_create($contextOptions);
    
    $handle = fopen($url, 'r', false, $context);
    

提交回复
热议问题