共计 329 个字符,预计需要花费 1 分钟才能阅读完成。
通常我们使用 Curl 来检查远程文件是否存在:
$ch = curl_init("http://www.baidu.com/favicon.ico"); | |
curl_setopt($ch, CURLOPT_NOBODY, true); | |
curl_exec($ch); | |
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
if ($retcode == 200) {// 文件存在 | |
} |
还有一种方法使用get_headers
$url = 'http://www.example.com/index.html'; | |
$header = get_headers($url); | |
if ($header && $header[0] == 'HTTP/1.1 200 OK') {// 文件存在 | |
} |
正文完