Getting Remote File Size 
Author Message
 Getting Remote File Size

How would you go about writing a perl script that would open a remote
image (from a url: ex. http://www.*-*-*.com/ ) and and
get a local perl script to get the file size (in bytes) and print it out

to the browser?  If someone could provide an example of how to do
this...it would be greatly appreciated.  Thanks in advance.

Thanx,
Jesse Rosenberger
Webmaster - Savalas Productions, Inc.
http://www.*-*-*.com/



Tue, 29 Aug 2000 03:00:00 GMT  
 Getting Remote File Size

Posted and Mailed:

A quick answer is to ftp over to www.perl.com
and look for isize.

HTH,
Sneex :)

Quote:

> How would you go about writing a perl script that would open a remote
> image (from a url: ex. http://www.yourdomain.com/myimage.gif) and and
> get a local perl script to get the file size (in bytes) and print it out

> to the browser?  If someone could provide an example of how to do
> this...it would be greatly appreciated.  Thanks in advance.

> Thanx,
> Jesse Rosenberger
> Webmaster - Savalas Productions, Inc.
> http://www.savalas.com




Wed, 30 Aug 2000 03:00:00 GMT  
 Getting Remote File Size

Well, I have spent the last couple hours searching around perl.com...but
have failed to figure out how to get perl to open a REMOTE url, and find
the size it in bytes, then I want to have the size printed out to the
users browser?  does anyone have any ideas besides perl.com...or if
that's all they have...exactly what section of perl.com should I be
looking in, although I have looked through most of it already.

Thanx,
Jesse Rosenberger

Quote:

> Posted and Mailed:

> A quick answer is to ftp over to www.perl.com
> and look for isize.

> HTH,
> Sneex :)


> > How would you go about writing a perl script that would open a
> remote
> > image (from a url: ex. http://www.yourdomain.com/myimage.gif) and
> and
> > get a local perl script to get the file size (in bytes) and print it
> out

> > to the browser?  If someone could provide an example of how to do
> > this...it would be greatly appreciated.  Thanks in advance.

> > Thanx,
> > Jesse Rosenberger
> > Webmaster - Savalas Productions, Inc.
> > http://www.savalas.com




Wed, 30 Aug 2000 03:00:00 GMT  
 Getting Remote File Size

Quote:

> Well, I have spent the last couple hours searching around perl.com...but
> have failed to figure out how to get perl to open a REMOTE url, and find
> the size it in bytes, then I want to have the size printed out to the
> users browser?  does anyone have any ideas besides perl.com...or if
> that's all they have...exactly what section of perl.com should I be
> looking in, although I have looked through most of it already.


> > Posted and Mailed:

> > A quick answer is to ftp over to www.perl.com
> > and look for isize.

i think sneex means the Image::Size module which analyzes image files
and returns their x,y sizes. the original poster wants the size of the
file itself and the file is remote. this cannot be done directly. you
need to get a directory listing (for ftp) or get the file for http. http
doesn't support getting just the size of a file.

so this is not a perl question and should be asked in some group like
comp.infosystems.www.authoring.cgi

hth,

uri

--
Uri Guttman                     SYStems ARCHitecture and Software Engineering

http://www.sysarch.com                (781) 643-7504 x*2  FAX: (781) 643-2710
Try the Best Search Engine on the Net -------->  http://www.northernlight.com



Thu, 31 Aug 2000 03:00:00 GMT  
 Getting Remote File Size

Quote:

> Well, I have spent the last couple hours searching around perl.com...but
> have failed to figure out how to get perl to open a REMOTE url, and find
> the size it in bytes, then I want to have the size printed out to the
> users browser?  does anyone have any ideas besides perl.com...or if
> that's all they have...exactly what section of perl.com should I be
> looking in, although I have looked through most of it already.

Make sure LWP (libwww-perl) is installed (if not, grab it from
CPAN). Then you can do stuff like this:

        use LWP::Simple;


            print "Content length is $results[1] bytes\n";
        } else {
            print "Retrieval failed\n";
        }

which should yield

        Content length is 2568 bytes

Scan the documentation that comes with LWP for more info. HTH.

_____________________________________________________________________




Thu, 31 Aug 2000 03:00:00 GMT  
 Getting Remote File Size

Since I totally misunderstood this question (I thought Jesse was on the
server he wanted the image size info from, I went down the wrong path to
help answer it.)  But, since I did get a server version working, no since in
wasting the code; so here is a server version of getting the file size --
Any File size :)

Man, does this OPEN a BIG security hole :)
/^Enjoy$/;
Sneex :)

#!/usr/local/bin/perl -w

use CGI qw(:all);
use strict;
# use diagnostics; # Display all diagnostics in browser anyways...

print header; # In case there is an early error...
my $basedir = '/drv2/usr/ns-home/docs'; # Limit the damage area...
$_ = query_string() if query_string();
my $wFile =  /=/;
$wFile = $';

# Some cool CGI.pm stuff - a plug for Lincoln's CGI.pm Module :)
if (accept())          { print "<P>Browser MIME List: &nbsp;", accept() }
if (auth_type())       { print "<BR>Authentication Type: &nbsp;",
auth_type() }
if (raw_cookie())      { print "<BR>Raw Cookie: &nbsp;", raw_cookie() }
if (path_info())       { print "<BR>Path Info: &nbsp;", path_info() }
if (path_translated()) { print "<BR>Path Translated: &nbsp;",
path_translated() }
if (query_string())    { print "<BR>Query String: &nbsp;", query_string() }
if (referer())         { print "<BR>Referrer: &nbsp;", referer() }
if (remote_addr())     { print "<BR>Remote Addr: &nbsp;", remote_addr() }
if (remote_ident())    { print "<BR>Remote Ident: &nbsp;", remote_ident() }
if (remote_host())     { print "<BR>Remote Host: &nbsp;", remote_host() }
if (remote_user())     { print "<BR>Remote User: &nbsp;", remote_user() }
if (request_method())  { print "<BR>Request Method: &nbsp;",
request_method() }
if (script_name())     { print "<BR>Script Name: &nbsp;", script_name() }
if (server_name())     { print "<BR>Server Name: &nbsp;", server_name() }
if (server_software()) { print "<BR>Server Software: &nbsp;",
server_software() }
if (virtual_host())    { print "<BR>Virtual Host: &nbsp;", virtual_host() }
if (server_port())     { print "<BR>Server Port: &nbsp;", server_port() }
if (user_agent())      { print "<BR>User Agent: &nbsp;", user_agent() }
if (user_name())       { print "<BR>User Name: &nbsp;", user_name() }

print "<P>What you are looking for &nbsp;";
print $wFile;
print "<P>What I found: &nbsp;";

my $erc = system("find $basedir -name $wFile -print > /tmp/results") / 256;

if ($erc) {
 print "<P>An Error occurred $erc $! <BR>";

Quote:
} else {

 open (inpFile, "/tmp/results") || die("<P>Can't open $! <BR>");
 while (<inpFile>) {
  chomp;
  $wFile =~ /^$basedir/;
  $wFile = $';
  print "<P>Found $_, with a size of ", (-s $_);
   # See if we can view it :)
  print "&nbsp;<img src=\"/$wFile\"></A><BR>";
 }
 close(inpFile);

Quote:
}

exit;

# End of code...

Quote:

> How would you go about writing a perl script that would open a remote
> image (from a url: ex. http://www.yourdomain.com/myimage.gif) and and
> get a local perl script to get the file size (in bytes) and print it out

> to the browser?  If someone could provide an example of how to do
> this...it would be greatly appreciated.  Thanks in advance.

> Thanx,
> Jesse Rosenberger
> Webmaster - Savalas Productions, Inc.
> http://www.savalas.com




Thu, 31 Aug 2000 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. HELP! Getting Remote File Size

2. getting remote file sizes

3. CGI.pm Bug: file upload file size mismatch when file size is close to buffer size

4. Getting File stats on a remote file

5. Fetch size of remote web page/file...

6. LWP remote file size

7. Getting files off remote servers

8. getting file fro ma remote computer ?

9. getting the results from a remote cgi script to a text file

10. Getting File Size

11. problem getting file size in forked code

12. (Q) getting a file's size in Perl

 

 
Powered by phpBB® Forum Software