use LWP::UserAgent;

sub GetFileSize{
        my $url=shift;
        $ua = new LWP::UserAgent;
        $ua->agent("Mozilla/5.0");
        my $req = new HTTP::Request 'HEAD' => $url;
        $req->header('Accept' => 'text/html');
        $res = $ua->request($req);
        if ($res->is_success) {
                 my $headers = $res->headers;
                 return $headers;
        }
return 0;
}


$link='http://www.abc.com/file.mp3';
$header = GetFileSize($link);

print "File size: ".$header->content_length." bytes\n";
exit;




On Thu, Nov 26, 2009 at 12:28 PM, raphael() <raphael.j...@gmail.com> wrote:

> Hi,
>
> I am writing a small script to download files of the web.
> How can I get the "file size" without downloading the file?
>
> use LWP::Simple;
> my $file = "http://www.abc.com/file.mp3";
> my @array = head($file);
> print "$array[1]\n";
>
> head() doesn't always returns all values?  why??
> Sometime there are all values some time @array is empty!
> Should I try LWP::UserAgent or is there any other way?
>

Reply via email to