php 判断远程文件是否存在

 PHP基础  2023-01-07  admin  506  683

php 判断远程文件是否存在

if (!function_exists('check_remote_file_exists')) {
    /**
     * 判断远程文件是否存在.
     * @param $url string http或https开头的绝对地址
     * @return string
     * @Date: 2020-07-31 16:47:06
     * @Author: code.newai.top
     */
    function check_remote_file_exists($url)
    {
        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_NOBODY, true);
        //curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
        $result = curl_exec($curl);

        //print_r($result);
        $bool = false;
        if ($result !== false) {
            $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
            if ($statusCode == 200) {
                $headInf = get_headers($url, 1);
                $time = strtotime($headInf['Last-Modified']);
                if ($time + 2 < time()) {
                    $bool = true;
                }
            }
        }
        curl_close($curl);

        return $bool;
    }
}


如果文章对您有帮助,点击下方的广告,支持一下作者吧!

转载必须注明出处:

php 判断远程文件是否存在 —— code.cent123.com

相关推荐


go 在Windows系统中交叉编译临时环境变量设置

go 编译临时环境变量设置并 交叉编译命令$env:GOOS=&quot;linux&quot;;$env:GOARCH=&quot;amd64&quot;;gobuild-ofilenametest.go$env:GOOS=&quot;linux&quot;;$env:GOARCH=&quot;amd64&quot;;`gobuild-ofilenametest.go`这两种方式 都是在Powe

phpstorm 设置 外部命令

C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.20.11781.0_x64__8wekyb3d8bbwe\wt.exe-d $ContentRoot$$ProjectFileDir$

点名工具,抽奖软件

点名工具,抽奖软件

酷炫的倒计时客户端

QQ: 425100867捐赠开发者: