Anish Kumar K. <[EMAIL PROTECTED]> asked:
> Is it possible to calculate the File SIZE which is from HTTP. 
> i.e if I wanted to know
> 
> file size of http://www.yahoo.com/images/a.gif from PERL..

Send a HEAD request for the URI and look at the
Content-Length header of the response object:

#!/usr/bin/perl -w

use strict;
use LWP::UserAgent;

my $url = 'http://us.i1.yimg.com/us.yimg.com/i/yahoo.gif';

my $ua = new LWP::UserAgent(timeout => 60);

my $response = $ua->head( $url );

if( $response->is_success ){
  print 'The image size is ' . $response->header('Content-Length') . " 
bytes.\n";
} else {
  die 'The request was unsuccessful: ' . $response->status_line;
}

__END__

HTH,
Thomas

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to