Jump to content

Image link verifying


Porl123

Recommended Posts

I've got a function at the moment which makes sure the avatar image link a user posts is either a jpeg, png, bmp or gif and it works fine with most links when they come from some sites but for some reason all imageshack.us links always return blank and I'm not sure why. Here's the function I'm using and if there's anything that you think might cause this happening any help would be appreciated. Thanks folks!

 

[pre]

function images($link) {

$info = @getimagesize($link);

if($info['mime'] == 'image/gif') {

$a = 1;

} elseif($info['mime'] == 'image/jpeg') {

$a = 1;

} elseif($info['mime'] == 'image/png') {

$a = 1;

} elseif($info['mime'] == 'image/wbmp') {

$a = 1;

} else {

$a = 0;

}

 

if($a == 1) {

$ret = $link;

} else {

$ret = '';

}

 

return $ret;

}

[/pre]

Link to comment
https://forums.phpfreaks.com/topic/154642-image-link-verifying/
Share on other sites

When I run it I get:

 

string(49) "http://img17.imageshack.us/img17/2729/porlhh7.gif"

 

returned which seems fine. I've even checked the headers that imageshack is sending using teh web dev toolbar and they look fine too.

 

I have noticed that sometimes imageshack is slow though so is possible your script may be timing out. :shrugs:

Link to comment
https://forums.phpfreaks.com/topic/154642-image-link-verifying/#findComment-813207
Share on other sites

http://uk2.php.net/getimagesize returns false and generates an E_NOTICE when the read fails or E_WARNING when the image is invalid so you could check for the false. I'd also prefix it with an @ to ensure that any errors are never displayed.

 

I suspect that there are more "proper" ways of doing this. I never like having to prefix code with @.

Link to comment
https://forums.phpfreaks.com/topic/154642-image-link-verifying/#findComment-813222
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.