Home  >  Article  >  Backend Development  >  How to use curl to determine whether a remote file exists in PHP_PHP Tutorial

How to use curl to determine whether a remote file exists in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:27:53893browse

PHP uses curl to determine whether the remote file exists. Please see the code below:

// Determine the remote file

Function check_remote_file_exists($url)

 {

$curl = curl_init($url);

// Do not retrieve data

curl_setopt($curl, CURLOPT_NOBODY, true);

// Send request

$result = curl_exec($curl);

 $found = false;

// If the request is not sent, it fails

 if ($result !== false) {

// Check again whether the http response code is 200

$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

 if ($statusCode == 200) {

 $found = true;

 }

 }

curl_close($curl);

return $found;

 }

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/815778.htmlTechArticlePHP uses curl to determine whether the remote file exists. Please see the code below: //Judge the remote file function check_remote_file_exists($ url) { $curl = curl_init($url); // Do not retrieve data cu...
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