php 判断远程文件是否存在
if (!function_exists('check_remote_file_exists')) { /** * 判断远程文件是否存在. * @param $url string http或https开头的绝对地址 * @return string * @Date: 2020-07-31 16:47:06 * @Author: code.cent123.com */ 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; } }