Read STDIN in perl/NT

Posted on 1998-09-12
Last Modified: 2008-02-01
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;

Question by:donb1
  • 3
  • 3
LVL 28

Expert Comment

ID: 1204838
you have to use binmode on NT when it's about binary data.

like in here:

open(OUTFILE, ">upload/test.gif");
binmode (OUTFILE);
syswrite (OUTFILE, $in{'upfile'}, length $in{'upfile'});


Author Comment

ID: 1204839
I am trying to upload a gif file over the internet to a particular folder in NT.  I use a form:
<form action="" method="POST" enctype="multipart/form-data">
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).

LVL 28

Accepted Solution

sybe earned 50 total points
ID: 1204840
I use cgi-lib to do that:

this is the code for the perl file:

require "./";
$cgi_lib'maxdata = 50000;         
$ret = &ReadParse;
open(OUTFILE, ">upload/test.gif");
binmode (OUTFILE);
syswrite (OUTFILE, $in{'upfile'}, length $in{'upfile'});

print &PrintHeader;
print &HtmlTop("File Upload Results");

print "$in{'upfile'}";

print "\n<P>File was uploaded<P>";

print &HtmlBot;


See for
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!


Author Comment

ID: 1204841
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.
LVL 28

Expert Comment

ID: 1204842

In the perlscript, change

$ret = &ReadParse;


$ret = &ReadParse(\%cgi_data,\%cgi_cfn,\%cgi_ct,\%cgi_sfn);

The the complete path of the uploaded file can be retrieved by:


You'll have to do some string processing before you have the actual name (because it is the complete path !).

See also

(that's where I got it from)


Author Comment

ID: 1204843
Thanks very much

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now