Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Answer: How can I transfer file from client? Futher problems inside...

by Corion (Pope)
on Jul 11, 2000 at 12:09 UTC ( #21931=categorized answer: print w/replies, xml ) Need Help??

Q&A > network programming > How can I transfer file from client? Futher problems inside... - Answer contributed by Corion

Of course, the canonical reply would be to use which handles all of this nasty stuff quite well and comes with about every Perl distribution I know. also takes care of the tempfile creation, removal and I guess that there are no backdoors or exploits in itself.

There are at least two things wrong with the code :
First, no error checking. Opening a file should always be done like this (in my holy opinion) :

local *FILE; open( FILE, "> $file" ) or die "Couldn't create '$file' : $!\n"; ... close( FILE );
Of course, it's not always adequate to die(), but at least a warn is in place and for tools or CGI stuff, a die isn't bad, as the stuff will show up in the error log of the server.

The second thing is, that the file will be clobbered under Win32, as it is used for binary data and no binmode() is used on the file handle. This will not affect writing ASCII data in any way and it will also have no effect under UNIX platforms.

Looking further through the code, I see that $form_data is printed to STDOUT instead of (as it maybe should be ?) to FILE. Maybe that's already the error... Also, because there won't be more (or less) bytes available on STDIN than $ENV{'CONTENT_LENGTH'} indicates, reading from STDIN could simply be done by using the following code :

{ local $/ = ""; $form_data = <>; }; # $form_data now contains the submitted stuff
But I would really use for such stuff like file submission !

Log In?

What's my password?
Create A New User
[marto]: I read about a case where people were at a launderette, or whatever they're called in the US, and as a joke, put their toddler in with the washing, then closed the door
[Your Mother]: (Work in progress.)
[marto]: unaware that the model in question started the cycle automatically, provided the money/token had already been provided
[marto]: CCTV footage of the joke gone wrong is used in educational materials now IIRC
[ambrus]: oiskuu: definitely not silly. have you ever tried to remove cat hair or dog hair from clothes? for many clothes, it's pretty hard, and running the washing machine with a cat inside would get the hair on everything.
[oiskuu]: YM, I'm interested in your questions... maybe start a a thread at polls.
[oiskuu]: marto, it ended badly? I doubt the power is easy to plug at those installations?
[marto]: oiskuu sadly yes

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (14)
As of 2017-12-18 14:58 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (488 votes). Check out past polls.