Home  >  Article  >  php教程  >  PHP利用curl判断远程文件是否存在的方法

PHP利用curl判断远程文件是否存在的方法

WBOY
WBOYOriginal
2016-06-13 09:33:171404browse

   PHP利用curl判断远程文件是否存在,请看下边的代码:

  //判断远程文件

  function check_remote_file_exists($url)

  {

  $curl = curl_init($url);

  // 不取回数据

  curl_setopt($curl, CURLOPT_NOBODY, true);

  // 发送请求

  $result = curl_exec($curl);

  $found = false;

  // 如果请求没有发送失败

  if ($result !== false) {

  // 再检查http响应码是否为200

  $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

  if ($statusCode == 200) {

  $found = true;

  }

  }

  curl_close($curl);

  return $found;

  }

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn