[ back to toc ]

Using LWP....

Date: 2002/01/07 19:31


I use LWP module to upload files from the local hard drive to the server
and this is done in a single window. I then want to open a separate window
which has the url of the web server. The first window needs to be open
since after the upload I want to rename the uploaded files on the local
hard drive (for this I use personal web server). So the urls of the two
windows differ.

I now face the problem that the script tag does not seem to work in the
LWP script. I am pasting the example script. Please tell me what I am
doing wrong.

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

use strict;

use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use CGI qw/:standard/;
my $query=new CGI;

my $ua = LWP::UserAgent->new;
$ua->agent("dvpr-upload/1.0 " . $ua->agent);

my $cdsid = 'mycdsid';
my $comment = 'This is a test.';
my $filename = 'example.txt';

my $dir="c:\\mydir\\data";
opendir DIR, $dir or die "Can't open directory $dir: $!\n";
my @files=grep !/^\./, readdir(DIR);
my $i;

if($files[$i]=~ /.db$/ )
my $filename=$dir.'\\'.$files[$i];

my $req = POST('http://myserver.com/upload-assessment.cgi',
Content_Type => 'form-data',
Content => [ name => $cdsid,
comment => $comment,
file => [ $filename, undef,
Content_type =>
"application/octet" ] ] );

#print $req->as_string;
my $res = $ua->request($req);
#print $res->as_string;


print $query->header();
print $query->start_html();
print "<script language='javascript'>var newWindow =
print $query->end_html();

Please reply as soon as possible...Thanks in advance


First of all check the printed result in the browser. You have to see the
JavaScript in the browser that you get the result viewing the source in
the browser.

On the other hand I would do something else:

1. I would write the JavaScript code the following way:

print <<'END';
<script language='javascript'>
var newWindow =

'END' instead of END because there is no variable in the string, thus it
need not be interpolated.

2. I would not use JavaScript and open a new window and leave an empty
window opened there. I would rather

print <<'END';
Status: 301 Permanently Moved
Location: 'http://myserver.com/uploaded-files.cgi
Content-Type: text/html


that redirects the already opened window to the URL.

As a matter of fact I see not apparent error in your code. To find it
would require to set up my PWS that I do not have time now. I hope you
will find your bug. I suspect it is because the string is interpolated
uselessly and Perl changes in it something.


[ back to toc ]