in reply to Upload files using CGI Module

The following example works for me.
use CGI; my $q = CGI->new; my $fileHandle = $q->upload('file'); my $file = $q->param('file'); my $bytesread; my $buffer; open FILE , ">YOUR_NEW_FILE"; while($bytesread = read($fileHandle, $buffer, 1024)) { print FILE $buffer; } close FILE

Replies are listed 'Best First'.
Re^2: Upload files using CGI Module
by rpike (Scribe) on Jan 09, 2008 at 17:38 UTC
    Thanks it worked. I'm not sure what line it was that was causing me the problem but I copied this and made the slight adjustments I needed and it worked. Does the while (<$filehandle>) { ... } work just as well or should I be using this form all the time? Thanks. Rob
      <$filehandle> also works. But in binary mode, reading large chunks of data may be more efficient.
      You are not interested in parsing the file line by line, and newline chars may be between very small groups of chars, so that would force you to do more disk accesses.
        That's what I was hoping would be the only difference. Thanks again.