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

前端 未结 22 2908
死守一世寂寞
死守一世寂寞 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:39

    function remote_file_exists($url){
       return(bool)preg_match('~HTTP/1\.\d\s+200\s+OK~', @current(get_headers($url)));
    }  
    $ff = "http://www.emeditor.com/pub/emed32_11.0.5.exe";
        if(remote_file_exists($ff)){
            echo "file exist!";
        }
        else{
            echo "file not exist!!!";
        }
    

提交回复
热议问题