OK guys,
Here is the last revision of my code. Finaly got it working:
Code:
/* Start hack Image RESIZE */
// Check to see if image exists
$link = str_replace(" " , "%20", $link);
$link = str_replace("&" , "%26", $link);
// Get host url name for fsockopen to see if server is reachable
$img_host=str_replace('http://','',$link);
$img_host=substr($img_host,0,strpos($img_host,'/'));
// Check is server is reachable and timeout in 5 seconds if not
if (@fclose(@fsockopen($img_host, 80, $fsockerr1, $fsockerr2, 5))) {
// Check if image is on server
if (@fclose(@fopen("$link", "rb"))) {
// Check image size and if oversize, change bbtag
$img_width = getimagesize($link);
if ($img_width[0] > 600) {
$navigator_user_agent = ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : '';
if (stristr($navigator_user_agent, "msie")) {
return '<a href="' . $link . '" target="_blank"><img src="' . $link . '" border="0" alt="' . $vbphrase['click_for_larger_image'] . '" style="width: expression(this.width > 600 ? 600 : true);" /></a>';
} else {
return '<a href="' . $link . '" target="_blank"><img src="' . $link . '" border="0" alt="' . $vbphrase['click_for_larger_image'] . '" style="max-width: 600px;" /></a>';
}
} else {
return '<img src="' . $link . '" border="0" alt="" />';
}
} else {
// Image not found
return '<table border="1" cellpadding="2" id="image_found"><tr><td><FONT color="#FF0000">' . $vbphrase['image_link_broken'] . '</font></td></tr></table>';
}
} else {
// Server is down
return '<table border="1" cellpadding="2" id="image_found"><tr><td><FONT color="#FF0000">' . $vbphrase['image_server_down'] . '</font></td></tr></table>';
}
/* End hack Image RESIZE */
// /* Original code: return '<img src="' . $link . '" border="0" alt="" />'; */
What it does:
Check if the database server is online
Check if the image is available
Check the width of the image
If > 600 width, resize to 600 and place a link under it to click for the orginal image
It doesn't touch the image when =< 600 width.
The problem with not being able to cope with spaces or ampersands in the url is solved.
If you are gonna use this, be sure to add the three phrases.
You can costumize the width that you want as limit for resizing by changing the three instanses of "600" in the code to the limit you want.
I don't want to take credit for this code because I did nothing else than changing the existing code that was allready there
Enjoy