in reply to Re: Uploading Files with CGI.pm results in 0 byte files
in thread Uploading Files with CGI.pm results in 0 byte files

Found the problem.

I was checking authentication using CGI::Session and creating a $cgi object with it.

Apparently, if you have form data and don't use the first CGI object you create you lose the upload, but retain all the additional data.

Learn something new every day. I've been creating multiple CGI objects for years without any problems. From now on i'll create just one and pass it around to functions as needed.
  • Comment on Re^2: Uploading Files with CGI.pm results in 0 byte files

Replies are listed 'Best First'.
Re^3: Uploading Files with CGI.pm results in 0 byte files
by friedo (Prior) on Nov 19, 2006 at 21:38 UTC
    That's because POST data comes into the program on STDIN, as opposed to the environment table which is used for GET data ($ENV{QUERY_STRING}). STDIN can only be read once, and so the first CGI object instantiated will suck it all up.

      That's because POST data comes into the program on STDIN, as opposed to the environment table which is used for GET data ($ENV{QUERY_STRING}). STDIN can only be read once, and so the first CGI object instantiated will suck it all up.

      friedo++

      Also, this is why app frameworks like CGI::Application and Catalyst are pure genious. In the case of CGI::Application, one says:

      $self->query

      and knows he has the right object.

      If a code base has this particular type of bug, I'd probably be willing to bet there is a host of other worse ones lurking. I know because I've written them :-)

      At a minimum, if CGI->new is being called more than once per request there are troubles. If it is being done with the session object, (sometimes) there are serious troubles.

      The session manager I use is used in production on a large quantity of computers. It has probably been debugged by more than 100 people. The following is an example usage:

      CGI::Application::Plugin::Session example

      Building frameworks is fun, but if you're trying to up your productivity, check out a perl web app framework.

      If you didnt read the link above, at least consider the following:

      http://search.cpan.org/search?query=CGI::Application::Plugin&mode=all

      There you'll find a html popup dbi profiler, database driven session based auth, heck even a CAPTCHA plugin.

      trwww
      -- beating on the perl web app framework drum