in reply to Creating GD::Image directly from CGI->upload()

CGI.pm uses its own hand rolled tempfile mechanism which is almost certainly the issue. See the package Fh around line 3000 of CGI.pm to see how this is hand rolled. If you are not using the HTML features then CGI::Simple gives you the same API but returns real IO::File objects which will work.

You can get the actual filename but you will have to hack into the CGI.pm object to do that. I suggest you don't. But if you want to Data::Dumper will let you see what you need to do to access the actual filename (it is under the .tmpfiles hash key in the object root). NB If $PRIVATE_TEMPFILES is set true then CGI.pm will unlink the underlying file, so you can only access it via the open handle that CGI.pm maintains.

If you want my 2c the simplest change is just to copy the file to a tmp file, make your GD:Image and unlink it. In relative terms the wait for the upload is the vast majority of the execution time, generating a tmp file is a trivial cost.

cheers

tachyon

  • Comment on Re: Creating GD::Image directly from CGI->upload()

Replies are listed 'Best First'.
Re^2: Creating GD::Image directly from CGI->upload()
by saberworks (Curate) on Oct 21, 2004 at 19:24 UTC
    Thanks tachyon. Yeah I guess I'll just do that - I would use CGI::Simple (I don't like CGI.pm much at all), but the code I'm working on was written by someone else and while they don't usually use the html generation parts of CGI.pm, I've seen a smattering of it here and there, so it's not really safe for me to do a drop-in replacement. I don't want to mess around with the internals of CGI.pm - if I do that I'll be even further away from my goal of eventually dropping it altogether.