Skip to content

Instantly share code, notes, and snippets.

@abbotto
Created August 16, 2013 12:55
Show Gist options
  • Save abbotto/6249647 to your computer and use it in GitHub Desktop.
Save abbotto/6249647 to your computer and use it in GitHub Desktop.
A function to see if a file exists with curl.
function file_alive($_path) {
$handle = curl_init($_path);
if (false === $handle) {return false;}
curl_setopt($handle, CURLOPT_HEADER, false);
curl_setopt($handle, CURLOPT_FAILONERROR, true);
curl_setopt($handle, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // request as if Firefox because some sites request a valid header from you
curl_setopt($handle, CURLOPT_NOBODY, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);
$alive = curl_exec($handle);
curl_close($handle);
return $alive;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment