How can one check to see if a remote file exists using PHP?

前端 未结 22 3039
死守一世寂寞
死守一世寂寞 2020-11-22 05:52

The best I could find, an if fclose fopen type thing, makes the page load really slowly.

Basically what I\'m trying to do is

22条回答
  •  半阙折子戏
    2020-11-22 06:38

    CoolGoose's solution is good but this is faster for large files (as it only tries to read 1 byte):

    if (false === file_get_contents("http://example.com/path/to/image",0,null,0,1)) {
        $image = $default_image;
    }
    

提交回复
热议问题