Skip to content

Instantly share code, notes, and snippets.

@amitmerchant1990
Last active May 31, 2017 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amitmerchant1990/6eed95fa9568edd1b332fabc9b3f87bc to your computer and use it in GitHub Desktop.
Save amitmerchant1990/6eed95fa9568edd1b332fabc9b3f87bc to your computer and use it in GitHub Desktop.
PHP : Check it remote file exists
<?php
// E.g. checkRemoteFileExists('https://avatars0.githubusercontent.com/u/3647841?v=3&s=460') == true
function checkRemoteFileExists($url){
$curl = curl_init($url);
//don't fetch the actual page, you only want to check the connection is ok
curl_setopt($curl, CURLOPT_NOBODY, true);
//do request
$result = curl_exec($curl);
$ret = false;
//if request did not fail
if ($result !== false) {
//if request was ok, check response code
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($statusCode == 200) {
$ret = true;
}
}
curl_close($curl);
return $ret;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment