?
Solved

Problem with POST method in Netscape7

Posted on 2003-03-27
8
Medium Priority
?
162 Views
Last Modified: 2013-12-25
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
0
Comment
Question by:reenadpatel
  • 3
  • 3
  • 2
8 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 8221108
What are the contents of upload.cgi?
0
 
LVL 1

Expert Comment

by:nbthanh
ID: 8224842
Hi reenadpatel
I found no error with your HTML file. Could you please post your upload.cgi's source?
0
 

Author Comment

by:reenadpatel
ID: 8224889
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
0
Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

 
LVL 1

Expert Comment

by:nbthanh
ID: 8225111
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.
0
 

Author Comment

by:reenadpatel
ID: 8226046
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
0
 
LVL 1

Expert Comment

by:nbthanh
ID: 8226078
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.
0
 
LVL 48

Accepted Solution

by:
Tintin earned 120 total points
ID: 8229179
If you find your server doesn't have CGI module installed, then get rid of yoru service provider as they are not earning their money.

Anyway, this is how I would rewrite it like:

#!/usr/bin/perl
use strict;
my $q = new CGI;
my $rmtuser = $ENV{'REMOTE_USER'};  


my $file = $q->param('uploadfile');
my $fh = $q->upload('uploadfile');

print $q->header;

open FILE, ">$rmtuser/$file" or die "Can not write to $rmtuser/$file $!\n";
binmode FILE;
print FILE <$fh>;
close FILE;

if (-z $rmtuser/$file) {
  print "<h1>Upload failed</h1>\n";
}
else
  print "<h1>Upload succeeded</h1>\n";
}  





0
 

Author Comment

by:reenadpatel
ID: 8240632
Thanks..it did work..it was really helpful.

Reena
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question