kiat has asked for the wisdom of the Perl Monks concerning the following question:
In the following code to write the contents of a file to a specified filename, the buffer size is given as 16_384 (from this node Re: File Upload - What Next?):
I've seen other numbers such as 1024 (1 kb). Is it an arbitrary number of bytes?use CGI: my $q = new CGI; use constant BUFFER_SIZE => 16_384; my $filename = $q->param( "filename" ) || die; # Assuming $filename is sanitized... my $fh = $q->upload( "file" ); my $buffer = ''; open(OUT,">/tmp/$filename"); binmode $fh; binmode OUTPUT; # Write contents to output file while ( read( $fh, $buffer, BUFFER_SIZE ) ) { print OUTPUT $buffer; }
Thanks in advance :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Ideal buffer size..
by waswas-fng (Curate) on Apr 22, 2004 at 04:00 UTC | |
by kiat (Vicar) on Apr 22, 2004 at 04:10 UTC | |
by Anonymous Monk on Apr 22, 2004 at 05:17 UTC | |
by William G. Davis (Friar) on Apr 22, 2004 at 05:16 UTC | |
by kiat (Vicar) on Apr 22, 2004 at 14:25 UTC |