in reply to File uploads, CGI::Application, File::TEMP and Uploadify

...but I can't save the file.

The temp file is automatically unlinked (when the handle goes out of scope), unless you tell it otherwise with UNLINK => 0.  Also, you don't need to open another TEMPFILE handle (which, btw, doesn't help with the unlink issue), as $tmp already is an opened handle to the file...  I.e. try

my $tmp = File::Temp->new( DIR => $self->cfg('UploadDirectory'), SUFFIX => '.zip', UNLINK => 0, ); # warn $tmp; # stringification gives filename ... print $tmp $buffer;

Replies are listed 'Best First'.
Re^2: File uploads, CGI::Application, File::TEMP and Uploadify
by Anonymous Monk on May 10, 2010 at 09:30 UTC
    Hey, you rock! Thank you for the advice! Do I need to binmode this somehow? I'm uploding zip files from windows, the file gets created but I can't unzip it, it claims to be corrupt.
    while (read ($fh, $buffer, $buffsize)) { print $tmp $buffer; $bytes_retrieved += bufsize; }
      Do I need to binmode this somehow?

      The documentation says the temp file is already being opened in binary mode, so theoretically, there should be no need to binmode it yourself.  You can of course still try it, though... (just say binmode $tmp; before printing to it.)  Ditto for the file handle $rh that you're reading from.