Home > Backend Development > PHP Tutorial > PHP uses curl to determine whether a remote file exists_PHP tutorial

PHP uses curl to determine whether a remote file exists_PHP tutorial

WBOY
Release: 2016-07-21 14:58:17
Original
804 people have browsed it

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

//Judge remote files
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/363880.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...
Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template