Link to home
Start Free TrialLog in
Avatar of reenadpatel
reenadpatel

asked on

Problem with POST method in Netscape7

Hi,

Sorry can somebody help me with this..
I am trying to upload a file to the server. THis is the html page and then i am calling a cgi script. Actually this works well in IE 6 but it gives problem in Netscape7. Here is the code. After i click the Upload File button it keeps going and i have some print statements in cgi which don;t get executed. It does not show anything and keeps running.
<html>
<title> Upload File </title>
<HEAD>
</HEAD>

<BODY>

<form name=upform method=POST action="upload.cgi" enctype="multipart/form-data">
<B>Select file:</B>
<BR><BR>
<input type=file name=uploadfile>
<BR><BR><BR>
<input type="submit" value=" Upload File ">
&nbsp;
<input type=button name="Cancel" value="Cancel" onclick="javascript:window.close()">
</form>

</BODY>
</html>

Thanks,
Reena
Avatar of Tintin
Tintin

What are the contents of upload.cgi?
Hi reenadpatel
I found no error with your HTML file. Could you please post your upload.cgi's source?
Avatar of reenadpatel

ASKER

Hi,

This is the code for upload.cgi

#!/usr/bin/perl

# environment variables
$request_method = $ENV{'REQUEST_METHOD'};
$rmtuser = $ENV{'REMOTE_USER'};  

# HTTP Content Header
print("Content-type: text/html\n\n");
print ("<html>\n");
print ("<title>Uploading File</title>\n");
print ("<head>\n");

print "$request_method\n";
print "$rmtuser\n";

#check request method
if($request_method eq "POST")  # POST method start
{
     binmode(STDIN);
     @inx = <STDIN>;    
     @filetest = <STDIN>;
     $str = @inx[1];
   $str1 = reverse $str;
    $filename1 = "";
    $currchar = "";
    $offset = 3;
    while ($currchar !~ /\\/) {
    $currchar = substr($str1, $offset, 1);
    if ($currchar !~ /\\/) {
    $filename1 = "$filename1$currchar";
    $offset++;
    }
    }
    $filename2 = reverse $filename1;
     splice(@inx,0,4);
   splice(@inx,$#inx,1);
    $in = join("",@inx);
    $in = substr($in,0,length($in) - 2);;
($in,$out) = split /Content-Disposition/, $in , 2;
($in,$out) = split /\-----------------------------/, $in , 2;
    print "$filename2\n";
    open(ff,">$rmtuser\/$filename2") or die "Could not open file";
    binmode(ff);
    print ff $in;
#    print $in;
    close(ff);
    system ("chmod 777 $rmtuser\/$filename2");
#    print ("Uploaded file ".$filename2);
print ("<script language=\"javascript\">\n");
print ("alert(\"File Uploaded\")\;\n");
print ("self.close()\;\n");
print ("<\/script>\n");
print ("<\/head>\n");
print ("<\/html>\n");
}
#exit main script
exit 0;

When i click on Upload File in Netscape 7 then it keeps running but then i cannot see the print statements which i have give initially in the CGI executed.

Pl. help.

Thanks,
Reena
Hi reenadpatel,
When upload ding via CGI, the web server will cache all POSTed data then execute your script. Thus your script won't run at all untill all data has been sent to the server. Therefor your script must wait untill the file is completely uploaded. If you're uploading a very large file, you have to wait for a long time. Whtn you testes, did you use the same file for IE and Netscape?

Next checking point: you try to stop your script just right after:
print "$request_method\n";
print "$rmtuser\n";
to check if Netscape send the varable $ENV{'REMOTE_USER'} correctly! (try to upload a very small file to test this!)

Moreover, some environmental varables may be vary between browsers. You may use this "standard" technique to upload file:
my $req = new CGI();
my $filein = $req->param('uploadfile');
if ($filein =~ /([^\/\\]+)$/) {
#because some browsers set filename=c:\fullpath\filename.ext
#some others just send filename.ext
#we should check this to get the actual filename
     $filename = $1;
}

#convert filename to lower case if you wish
$filename = lc($filename);

open(FILE, ">fileout.ext");
while (my $bytesread = read($filein, my $buffer, 4096)) {
     print FILE $buffer;
}
close(FILE);

The problem with your scripts is that IE and Netscape sent filename in different ways which caused your script trapped into a infinitive loop!

Hope this help.
Hi,

Thanks for the reply. But I do not have any modules installed in my Perl installation.

So I cannot use new CGI. I want to use STDIN to do this..Can u suggest me how to do that?

Reena
Hi reenadpatel,

CGI module is a standard module of Perl. It's so strange that your server doesn't have the CGI module installed! Please check this with your server's admin. A web server what supports Perl *must* have CGI module installed!
(or you may ask the server's admin if you can install it by yourself).

Hope this help.
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks..it did work..it was really helpful.

Reena