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

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

WBOY
Release: 2016-06-13 09:33:17
Original
1464 people have browsed it

   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;

  }

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template