Andre_br has asked for the wisdom of the Perl Monks concerning the following question:

Hello folks,

I´m going nuts with this one: just rebuilt my dev machine and now my file upload scripts started to record CGItemp*** files at my scripts directory.

CGItemp6662 CGItemp6667 ...

What's happening here? Any ideas how to solve it? I´m lost.

Thanks a lot

André

Replies are listed 'Best First'.
Re: filehandles being recorded as CGItemp files
by bart (Canon) on Apr 28, 2006 at 20:50 UTC
    It looks like CGI uses your current directory as the directory for temporary files, likely because it can't find any other directory it can use. See the source of that module, the sub find_tempdir, how it tries to find a directory.

    Why? No idea. Maybe it's because you're running your script under taint mode.

    Anyway, take a look at this line in CGI.pm:

    # HARD-CODED LOCATION FOR FILE UPLOAD TEMPORARY FILES. # UNCOMMENT THIS ONLY IF YOU KNOW WHAT YOU'RE DOING. # $CGITempFile::TMPDIRECTORY = '/usr/tmp';
    That would certainly fix it.
      Hello Bart and Ahmad

      It was weird that this started happening now, as I could swear it didn´t before, with the same code. But I just could solve it by closing the filehandle of the uploaded file, like this:

      ... close PHOTO; close $photocover;
      Now the file still gets created at my scripts dir, but is deleted right away, when I close the handle.

      But anyway, thanks a lot for the ideas.

      André

Re: filehandles being recorded as CGItemp files
by ahmad (Hermit) on Apr 28, 2006 at 18:17 UTC

    Hello ,

    post your code and let's see what's the problem

    most likely it's due to use of "import_names" function with CGI.PM module

    bye

      Sure, here is my code:
      # ... use CGI; my $q = new CGI; my $namecover = check_input( $q->param("cover") ); my $photocover = $q->upload("cover"); $namecover = lc $namecover; my ($radical, $extension) = split (/\./, $namecover); $namecover_system = "$record_id.$extension"; # this record_id comes fr +om the database $namecover_system = untaint ( $namecover_system ); # the -T switch wou +ldn´t work without this; the untaint() is a sub I created to untaint +the data open (PHOTO,">../images/covers/$namecover_system") || die $!; binmode PHOTO; while (<$photocover>) { print PHOTO; } close PHOTO; # ...
Re: filehandles being recorded as CGItemp files
by Anonymous Monk on Aug 15, 2008 at 18:41 UTC
    Andre,

    The following is a quik-fix. While not kosher, it works
    flawlessly. Better than spending a month looking for an
    answer that isn't there. PERL could be a really good
    language is there was so much crap it it.


    sub DeleteTemp {
      $dirtoget="./";
      opendir(IMD, $dirtoget) || die("Cannot open directory");
      @thefiles= readdir(IMD);
      closedir(IMD);
      foreach $curname (@thefiles)
        {
          $temp = substr($curname,0,7);
          if ($temp eq "CGItemp"){unlink($curname)}
        }
      }

    I would't suggest using this for any directory that contains
    numerous files though, as it will use up server execution
    time, but if you only have a few resident files, you
    should have no problem.

    Besides, I heard that this problem only exits on Windows
    based servers. Unix is supposed to remove its old temp files

    I did it this way because my scripts are going to run
    on over a thousand servers, and I haven't got time to
    play games altering every script to cover PERL's crap.

    Hope this helps you!

    Tom