Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI.pm on NT( is a nightmare)

Status
Not open for further replies.

jez

Programmer
Apr 24, 2001
370
VN
Hi there,

I have been tearing my hair out for over a week now as I wrote a simple upload script in perl to run on a win2k IIS 5 box.
It worked.
No changes to the script or the server and now it doesn't work. I have tried to fix it but with nothing being different I don't know what to change.

I say it doesn't work, but in fact it does but without writing any information to the file, uploading a 0 byte file to the server, in the right place with the right name.
And because it works, (for log purposes), non of my well placed error flags comes up and no helpful info is in the logs.

I can't find anybody who has any idea why this might be.
PLEASE HELP!!
I have seen this problem before on free webspace when you are obliged to use a browser form to upload your documents, however non of the webmasters of these places have responded to my emailed request for help. I beleieve it is an NT problem as I have tried downloaded 'upload' scripts with the same result.

Any help would be greatly apprecited.

Jez
 
how about giving us a look at the code? Not, 10 miles of it, but the relevant parts.

If it worked once it will work again.

If you are new to Tek-Tips, please use descriptive titles, check the FAQs,
and beware the evil typo.
 
OK here is the code;-

$ufile = param('upld'); ## this is the file field on the form
if ($ufile) { &uploading($ufile); }

sub uploading {
&mkuplp(); ## this makes the remote upload path
$_[0] =~m/.*[\/\\](.*)$/;
$nname = $1;
open (UPFILE, ">$uploadpath/$nname") or oops("Can't open upload file handle: $!");
flock(UPFILE, LOCK_EX);
binmode(UPFILE);
while (<$ufile>) {
print UPFILE; }
close UPFILE;
}

## this is my code for uploading, when it stopped working I thought that it might be that my code wasn't robust enough so I used a separate library file that contained another upload subroutine.

for this other method the code was;-

sub uploading {

&mkuplp;
my $query = new CGI;
my $filename = $query->param('upld');
#$filename =~ s/(.+)([^\/\\])$/$2/g;
$filename =~s/.*[\/\\](.*)$/$1/g;
my $results = &psupload($uploadpath, 'upld');
if($results == 1) {
$lastaction = qq~Last Action: <b>$filename</b> Uploaded~;
} else {
$lastaction = qq~Last Action: Upload failed, because: $results~;
}
}

## and ....
sub psupload {
my $path = shift;
my $inputfieldname = shift;
my $newname = shift;
my $maxsize = shift;
if($path) {
if($inputfieldname) {
my $req = new CGI;
if($req->param($inputfieldname)) {
my $file = $req->param($inputfieldname);
my $filename = $file;
$filename =~ s/^.*(\\|\/)//;
$filename =~ s/ +/\_/g;
$filename = $newname if $newname;
if(open(OUTFILE, &quot;>$path/$filename&quot;)) {
binmode(OUTFILE);
while (my $bytesread = read($file, my $buffer, 1024)) {
print OUTFILE $buffer;
}
close (OUTFILE);
if($maxsize > 0) {
if((-s &quot;$path/$filename&quot;) > ($maxsize * 1024)) {
unlink(&quot;$path/$filename&quot;);
return(&quot;The uploaded file was too big and has been removed.&quot;);
} else {
return(1);
}
} else {
return(1);
}
} else {
return(&quot;The subroutine could not open the destination file: $path/$filename&quot;);
}

} else {
return(&quot;The upload form was submitted without a file being uploaded.&quot;);
}
} else {
return(&quot;The subroutine was not told the name of the form input field so that it could look for the uploaded file.&quot;);
}
} else {
return(&quot;The subroutine was not told the absolut path to the directory where the uploaded file should be stored.&quot;);
}
}

1;
###########

this second method was a prewritten download and the author has also been looking into this but couldn't find a reason either.


Sorry about the miles of code but you did ask.


Cheers

Jez
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top