Subject: | Windows 7 and CGI.PM undefined upload handle |
Date: | Wed, 21 Apr 2010 20:01:12 +0800 |
To: | <bug-CGI.pm [...] rt.cpan.org> |
From: | "Jason Rose" <j [...] imperial.cc> |
Hi,
It appears that CGI.PM has a platform specific issue with Windows 7,
possibly only 64-bit version, in that it always gives undefined handle when
doing a $query->upload{field_name'}.
Observations:
. My code works fine on Windows XP 32bit running all Apache and
ActivePerl 5.8/5.10 versions laptop dev environment
. My code works fine on Linux Apache build running on B luehost.com
hosted solution
. Key point: the code works, but has issues on Windows 7 64-bit
unless you downgrade to ~v3.25 (I discovered this when rebuilding my dev
environment)
Potentially useful information (from local dev Win7-64 evironment using 3.48
and 3.49 CGI.PM)
. Tried multiple versions of Apache 2.x - no versions worked.
. Tried multiple versions of 5.8/5.10 ActiveState PERL (both 32-bit
and 64-bit versions) - no versions worked
. $ENV{CONTENT_LENGTH} always returns the correct number, so the
multipart/form-data and content upload is ok.
. When uploading a 1Gb file, I do see the CGIxxxx temp file in
C:\Windows\temp increasing in size. so it's not permissions issue with
Windows 7
. The problem seems to be that the CGIxxx temp file is deleted
instantly before an upload handle is generated
. In some versions of CGI.PM (I can't tell you the exact one, but
between 3.29 and 3.39 the CGIxxx temp file is written into the local script
folder instead of a temp folder. The problem there is two-fold: it still
doesn't return an upload handle and it doesn't delete the temp file either!
CODE
$filename = $q->param('Hfile');
$type = $q->uploadInfo($filename)->{'Content-Type'};
$tmpfilename = $q->tmpFileName($filename);
$filesize=-s $tmpfilename;
$ZLOG.="Received file '$in{Hfile}' according to \$ENV{CONTENT_LENGTH} is
size $ENV{'CONTENT_LENGTH'}<BR>";
$ZLOG.="Running CGI.PM $CGI::VERSION<BR>";
$ZLOG.="Temporary file name is '$tmpfilename' and the type is '$type' with
size of '$filesize'. <BR>";
$lightweight_fh = $q->upload('Hfile');
$ZLOG.="The handle is '$lightweight_fh'<BR>";
FAILED OUTPUT ON WIN7-64 DEV PLATFORM
Received file ' httpd.conf ' according to $ENV{CONTENT_LENGTH} is size 19324
Running CGI.PM 3.49
Temporary file name is 'C:\Windows\TEMP\CGItemp63983' and the type is
'text/plain' with size of ''.
The handle is ''
SUCCESSFUL OUTPUT ON LINUX BLUEHOST AND WINXP PLATFORM
Received file 'httpd.conf' according to $ENV{CONTENT_LENGTH} is size 19324
Running CGI.PM 3.49
Temporary file name is '/usr/tmp/CGItemp30111' and the type is 'text/plain'
with size of '18847'.
The handle is 'httpd.conf'
534 bytes loaded.
Relevant external post
http://forums.devshed.com/perl-programming-6/cgi-upload-problem-on-windows-c
omputer-cgi-pm-related-669763.html#post2451887