On all my Windows servers, except for one machine, when I execute the following code to allocate a temporary files folder:
use CGI;
my $tmpfile = new CGITempFile(1);
print "tmpfile='", $tmpfile->as_string(), "'\n";
The variable $tmpfile
is assigned the value '.\CGItemp1'
and this is what I want. But on one of my servers it's incorrectly set to C:\temp\CGItemp1
.
All the servers are running Windows 2003 Standard Edition, IIS6 and ActivePerl 5.8.8.822 (upgrading to later version of Perl not an option). The result is always the same when running a script from the command line or in IIS as a CGI script (where scriptmap .pl
= c:\perl\bin\perl.exe "%s" %s
).
How I can fix this Perl installation and force it to return '.\CGItemp1
' by default?
I've even copied the whole Perl folder from one of the working servers to this machine but no joy.
I checked the 'TMP
' and 'TEMP
' environment variables and also $ENV{TMP}
and $ENV{TEMP}
and they're identical.
From command line they point to the user profile directory, for example:
C:\DOCUME~1\[USERNAME]\LOCALS~1\Temp\1
When run under IIS as a CGI script they both point to:
c:\windows\temp
In registry key HKEY_USERS/.DEFAULT/Environment
, both servers have:
%USERPROFILE%\Local Settings\Temp
The ActiveState implementation of CGITempFile()
is clearly using an alternative mechanism to determine how it should generate the temporary folder.
The real problem is with the CGI.pm
module and attachment handling. Whenever a file is uploaded to the site CGI.pm
needs to store it somewhere temporary. To do this CGITempFile()
is called within CGI.pm
to allocate a temporary folder. So unfortunately I can't use File::Temp
. Thanks anyway.
That helped a bunch. I did have a quick scan through the CGI.pm
source earlier but your suggestion made me go back and look at it more studiously to understand the underlying algorithm. I got things working, but the oddest thing is that there was originally no c:\temp
folder on the server.
To obtain a temporary fix I created a c:\temp
folder and set the relevant permissions for the website's anonymous user account. But because this is a shared box I couldn't leave things that way, even though the temp files were being deleted. To cut a long story short, I renamed the c:\temp
folder to something different and magically the correct '.\
' folder path was being returned. I also noticed that the customer had enabled FrontPage extensions on the site, which removes write access for the anonymous user account on the website folders, so this permission needed re-applying. I'm still at a loss as to why at the start of this issue CGITempFile()
was returning c:\temp
, even though that folder didn't exist, and why it magically started working again.
Thanks in advance
Kevin