lucianovalenca
7/1/2014 - 1:41 AM

cURL

cURL

// Check if file exists

function exists($uri)
{
  $ch = curl_init($uri);
  curl_setopt($ch, CURLOPT_NOBODY, true);
  curl_exec($ch);
  $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  curl_close($ch);
  
  return $code == 200;
}
// Download a URL's Content

function get_data($url)
{
 $ch = curl_init();
 $timeout = 5;
 curl_setopt($ch,CURLOPT_URL,$url);
 curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
 curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
 $data = curl_exec($ch);
 curl_close($ch);
 return $data;
}

// Usage:
$returned_content = get_data('http://davidwalsh.name');