Before showing an image in the forum, the code:
1: checks if the image actually exists (to prevent an error on 2)
2: checks the size of the image
3: if the image is to large add height and width to the images to fit it in the forum, and maintain proportions
1 is code I found as freeware on the internet, and it sends a head request. the php code (with the head part) is:
function remote_file_exists ($url)
{
/*
Return error codes:
1 = Invalid URL host
2 = Unable to connect to remote host
*/
$head = "";
$url_p = parse_url ($url);
if (isset ($url_p["host"]))
{ $host = $url_p["host"]; }
else
{ return 1; }
if (isset ($url_p["path"]))
{ $path = $url_p["path"]; }
else
{ $path = ""; }
$fp = fsockopen ($host, 80, $errno, $errstr, 20);
if (!$fp)
{ return 2; }
else
{
$parse = parse_url($url);
$host = $parse['host'];
fputs($fp, "HEAD ".$url." HTTP/1.1\r\n"

;
fputs($fp, "HOST: ".$host."\r\n"

;
fputs($fp, "Connection: close\r\n\r\n"

;
$headers = "";
while (!feof ($fp))
{ $headers .= fgets ($fp, 128); }
}
fclose ($fp);
$arr_headers = explode("\n", $headers) ;
$return = false;
if (isset ($arr_headers[0]))
{ $return = strpos ($arr_headers[0], "404"

=== false; }
return $return;
}
Let me know how I can improve this code. Thanks in advance.
Edit: hmmm, immediately found another bug: there should be no smileys in code.
Please do not PM, IM or email me for support (they will go unread/ignored). Use the forum for support.