]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/attachment.pm
attachment: Support perl 5.8's buggy version of CGI.pm.
[ikiwiki.git] / IkiWiki / Plugin / attachment.pm
index 84bf643905f75dccf9122dc4a91bbfc201cc7079..ef6d79a9c52a1db7006d223730a1636c6ab71bf6 100644 (file)
@@ -89,9 +89,17 @@ sub formbuilder (@) { #{{{
                # This is an (apparently undocumented) way to get the name
                # of the temp file that CGI writes the upload to.
                my $tempfile=$q->tmpFileName($filename);
-               
                if (! defined $tempfile || ! length $tempfile) {
-                       error("failed to determine tempfile name");
+                       # perl 5.8 needs an alternative, awful method
+                       if ($q =~ /HASH/ && exists $q->{'.tmpfiles'}) {
+                               foreach my $key (keys(%{$q->{'.tmpfiles'}})) {
+                                       $tempfile=$q->tmpFileName(\$key);
+                                       last if defined $tempfile && length $tempfile;
+                               }
+                       }
+                       if (! defined $tempfile || ! length $tempfile) {
+                               error("CGI::tmpFileName failed to return the uploaded file name");
+                       }
                }
 
                $filename=IkiWiki::titlepage(
@@ -145,7 +153,7 @@ sub formbuilder (@) { #{{{
                                        # even that doesn't always work,
                                        # fall back to opening the tempfile
                                        $fh=undef;
-                                       open($fh, "<", $tempfile) || error("failed to open $tempfile: $!");
+                                       open($fh, "<", $tempfile) || error("failed to open \"$tempfile\": $!");
                                }
                        }
                        binmode($fh);