donb1
asked on
Read STDIN in perl/NT
I am trying to read STDIN with the following code: It worked on unix system but now does not work on NT. STDIN contains a .jpg file of about 10K. How can I get STDIN into $input??
$len = 0;
$input = '';
while ($len != $ENV{'CONTENT_LENGTH'}) {
$buf = '';
$len += sysread(STDIN, $buf, $ENV{'CONTENT_LENGTH'});
$input .= $buf;
}
$len = 0;
$input = '';
while ($len != $ENV{'CONTENT_LENGTH'}) {
$buf = '';
$len += sysread(STDIN, $buf, $ENV{'CONTENT_LENGTH'});
$input .= $buf;
}
ASKER
I am trying to upload a gif file over the internet to a particular folder in NT. I use a form:
<form action="pictur.pl" method="POST" enctype="multipart/form-da ta">
The gif file should be in <STDIN> along with some other form data -- How do I get it out of <STDIN>? On a unix system, I use the code in my original question. On an NT sysem, I only get a very small part of it (and even text is limited to about 4K).
<form action="pictur.pl" method="POST" enctype="multipart/form-da
The gif file should be in <STDIN> along with some other form data -- How do I get it out of <STDIN>? On a unix system, I use the code in my original question. On an NT sysem, I only get a very small part of it (and even text is limited to about 4K).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK, that really works great. One more question,
How can I get the name of the file that the person sent?
ie, the form field is a "file" field and contains the name of the file he uploaded. $in{'upfile'} is the file itself. I also need the name of the file, if possible.
Thanks
How can I get the name of the file that the person sent?
ie, the form field is a "file" field and contains the name of the file he uploaded. $in{'upfile'} is the file itself. I also need the name of the file, if possible.
Thanks
ok
In the perlscript, change
$ret = &ReadParse;
to:
$ret = &ReadParse(\%cgi_data,\%cg i_cfn,\%cg i_ct,\%cgi _sfn);
The the complete path of the uploaded file can be retrieved by:
$cgi_cfn{'upfile'}
You'll have to do some string processing before you have the actual name (because it is the complete path !).
See also http://cgi-lib.stanford.edu/cgi-lib/ex/perl5/fup.cgi.txt
(that's where I got it from)
In the perlscript, change
$ret = &ReadParse;
to:
$ret = &ReadParse(\%cgi_data,\%cg
The the complete path of the uploaded file can be retrieved by:
$cgi_cfn{'upfile'}
You'll have to do some string processing before you have the actual name (because it is the complete path !).
See also http://cgi-lib.stanford.edu/cgi-lib/ex/perl5/fup.cgi.txt
(that's where I got it from)
ASKER
Thanks very much
like in here:
open(OUTFILE, ">upload/test.gif");
binmode (OUTFILE);
syswrite (OUTFILE, $in{'upfile'}, length $in{'upfile'});
close(OUTFILE);