Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help stop the X from marking the non-existing image

Status
Not open for further replies.

Zas

Programmer
Oct 4, 2002
211
US
The users simple input an image url, and I want the image to come up valid everytime. The reason:
use LWP::Simple;
my $content = get $url;
die "Couldn't get $url" unless defined $content;

doesn't work is because that it dies if its nothing, but it goes through if its a bad image url, or just a folder, instead of dieing.

So my question is simple. How can I can I make a statement that determines if an image will produce something, or just an X box, or invalid image.
furthermore: if($url =spiffycommand=) { print "Good image, continue"; } else { print "Bad image. Go 'back'!"; exit; }

Happieness is like peeing your pants.
Everyone can see it, but only you can feel the warmth.
 
You could use [tt]head[/tt] instead of [tt]get[/tt] and make sure that the first element of the returned array starts with "image"

For example:
Code:
use LWP::Simple;
my ($type) = head $url;
if ($type =~ /^image/) {
  # do stuff
}
 
Hey, works like a charm, thanks!

Happieness is like peeing your pants.
Everyone can see it, but only you can feel the warmth.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top