Porl123 Posted April 18, 2009 Share Posted April 18, 2009 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 More sharing options...
soak Posted April 18, 2009 Share Posted April 18, 2009 Can you post an example imageshack link please? Link to comment https://forums.phpfreaks.com/topic/154642-image-link-verifying/#findComment-813188 Share on other sites More sharing options...
Porl123 Posted April 18, 2009 Author Share Posted April 18, 2009 Yeah this is the first one I tested it with: http://img17.imageshack.us/img17/2729/porlhh7.gif Link to comment https://forums.phpfreaks.com/topic/154642-image-link-verifying/#findComment-813191 Share on other sites More sharing options...
soak Posted April 18, 2009 Share Posted April 18, 2009 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 More sharing options...
Porl123 Posted April 18, 2009 Author Share Posted April 18, 2009 That might have something to do with it because I've noticed it takes a few extra seconds to load the page that function's used on. :X no idea how I'd fix that though Link to comment https://forums.phpfreaks.com/topic/154642-image-link-verifying/#findComment-813215 Share on other sites More sharing options...
soak Posted April 18, 2009 Share Posted April 18, 2009 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 More sharing options...
Porl123 Posted April 18, 2009 Author Share Posted April 18, 2009 Sorry I've taken so long to reply, something weird was happening when I refreshed. Would you be able to show me an example? I've read the page but I'm not quite sure how I'd do that. Thanks man Link to comment https://forums.phpfreaks.com/topic/154642-image-link-verifying/#findComment-813321 Share on other sites More sharing options...
Porl123 Posted April 18, 2009 Author Share Posted April 18, 2009 No ideas? Link to comment https://forums.phpfreaks.com/topic/154642-image-link-verifying/#findComment-813340 Share on other sites More sharing options...
soak Posted April 18, 2009 Share Posted April 18, 2009 Apologies, you've got the @ there already. you just need to check if $info is false : if ($info === false) { // do stuff } Not sure what you'd do other than let the user try again though. Link to comment https://forums.phpfreaks.com/topic/154642-image-link-verifying/#findComment-813342 Share on other sites More sharing options...
Porl123 Posted April 18, 2009 Author Share Posted April 18, 2009 Still makes it so imageshack links can't be posted though shame, ah well. Thanks for your help man Link to comment https://forums.phpfreaks.com/topic/154642-image-link-verifying/#findComment-813346 Share on other sites More sharing options...
soak Posted April 18, 2009 Share Posted April 18, 2009 Like I said above though, it worked for me. Maybe imageshack was just having a bad day when you tested? Link to comment https://forums.phpfreaks.com/topic/154642-image-link-verifying/#findComment-813349 Share on other sites More sharing options...
Porl123 Posted April 18, 2009 Author Share Posted April 18, 2009 Yeah I'm sure imageshack links have worked before but recently they don't even get past the verification Link to comment https://forums.phpfreaks.com/topic/154642-image-link-verifying/#findComment-813353 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.