View Single Post
Old 09-08-2009, 02:32 PM  
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085
Jeeesus peoples. This is a hack of a slightly-better-than-my-above for just checking for the files' existence, based upon code at PHP.net; I figured this thread should die a horrible death, so here ya go.

Code:
function http_file_exists($url=FALSE) {
  // Bad URL, bail.
  if (!(@parse_url($url))) return FALSE;
  // No cURL, bail.
  if (!(function_exists('curl_init'))) return FALSE;
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL,$url);
  curl_setopt($ch, CURLOPT_NOBODY, 1);
  curl_setopt($ch, CURLOPT_FAILONERROR, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  return (curl_exec($ch) !== FALSE) ? TRUE : FALSE;
}
Here's even a (shitty) working example:

Code:
$urltest = array ("http://www.google.com/logo.gif", "http://www.google.com/intl/en_ALL/images/logo.gif");

foreach ($urltest as $url) {
  echo http_file_exists($url) ? "$url exists.\n" : "$url is a 404.\n";
}
exit;
Code:
http://www.google.com/logo.gif is a 404.
http://www.google.com/intl/en_ALL/images/logo.gif exists.
Can this go away now pls?
__________________
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote