Sunday, August 3, 2008

CGItemp**** issue in file upload

Sometimes your file upload script produces temp files named CGItemp**** in the server (this happed to one of my Perl file upload script (cgi) running in a windows server).

So I did some search in the Internet about the problem. Many people faced the same problem and most of them choose a simple solution. That is to delete those files using a program or manually. After spending some more time, I found that those temp files are filehandles that are being recorded in the server. Though the CGI.pm file should have taken care of it (i.e. delete those files automatically).

I found that in my code I have opened a file handle which must be closed in order to get rid of this problem.

my $upload_file_handle = $q->upload("file_name");

when this variable (file handle) is not required any more, it should be closed.

So I added the line at the end of upload function:

close $upload_file_handle;

It solved the problem!

1 comment:

Unknown said...

This really does solve the problem on Windows servers. Thanks for the tip. I had already tried various settings in CGI.pm to no avail and was staying up way to late worrying about this.