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] Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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: Quote Link to comment 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 Quote Link to comment 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 @. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Porl123 Posted April 18, 2009 Author Share Posted April 18, 2009 No ideas? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.