Code:
<?php if(file_exists("http://www.site.com/images/$id/misc6.jpg")){ DO THIS }?>
EDIT: Note... $id is assigned above this statement.
<?php if(file_exists("http://www.site.com/images/$id/misc6.jpg")){ DO THIS }?>


[b]Example #3 getimagesize (URL)[/b]
<?php
$size = getimagesize("http://www.example.com/gifs/logo.gif");
// if the file name has space in it, encode it properly
$size = getimagesize("http://www.example.com/gifs/lo%20go.gif");
?>
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.site.com/blah/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch,CURLOPT_VERBOSE, FALSE);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$pageData=curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
switch ($statusCode) {
case 404:
filemissing()...
break;
case 401:
authreq();
break;
default:
whatev();
}
$file_url = "http://www.site.com/images/{$id}/misc6.jpg";
$file_exists = is_array($file_url);
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;
}
$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;
http://www.google.com/logo.gif is a 404. http://www.google.com/intl/en_ALL/images/logo.gif exists.
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;
}
$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;
http://www.google.com/logo.gif is a 404. http://www.google.com/intl/en_ALL/images/logo.gif exists.

Comment