in reply to Re: CGI upload and mod_perl
in thread CGI upload and mod_perl

You might not want to suggest to others to use that bit of code. Slurping an entire uploaded file into a scalar is a Bad Thing(Anyone know of a trademark on this? {grin}). What if I want to upload a 10MB file? You're going to have to hold 10MB in memory. Bad. Instead, you should be using something like this, dealing with one line at a time:

my $file = $cgi->param('datei'); my $fh = $cgi->upload('datei'); while (my $text = <$fh>) { # Do something... like this maybe: print $out_file $text; }

You might even want to consider looking at read() to read in a specific number of bytes on each pass through the loop. I generally don't go as far as to do that though. So what if my binary uploads might slurp a little more if there's a large chunk of fle with no newlines in it? :) (P.S: I won't even pretend to know how frequently newlines appear in a binary file. All I know is that they are there.)


If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, reply to this node or /msg me to tell me what is wrong with the post, so that I may update the node to the best of my ability. If you do not inform me as to why the post deserved a downvote, your vote does not have any significance and will be disregarded.

Replies are listed 'Best First'.
Re: Re^2: CGI upload and mod_perl
by hv (Prior) on Feb 20, 2003 at 18:47 UTC

    Sorry, perhaps that example wasn't good for general use. In my case the file's contents are going to be pumped straight into a database blob, and I don't see a useful alternative to grabbing the whole file - trying to sysread a chunk at a time to do repeated appends on the database field seems like overkill. I'm somewhat protected also because I've got an authenticated user before it gets this far.

    Hugo
Re^3: CGI upload and mod_perl
by Tomte (Priest) on Feb 20, 2003 at 12:31 UTC

    Good to know {evil-grin}, if I know one of your scripts is running I can feed it into oblivion with non-newline bytes {mad_laughter}.
    As a rule of thumb: You never know!

    regards,
    tomte