]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/attachment.pm
another try at dealing with CGI.pm problem
[git.ikiwiki.info.git] / IkiWiki / Plugin / attachment.pm
index cb762e453e9f92c368fed3784c1ad5820455e6f6..ed1cd61fe567c3d5cf845e5c647850de8556aa26 100644 (file)
@@ -34,7 +34,8 @@ sub formbuilder_setup (@) { #{{{
                # Start with the attachments interface toggled invisible,
                # but if it was used, keep it open.
                if ($form->submitted ne "Upload Attachment" &&
-                   ! length $q->param("attachment_select")) {
+                   (! defined $q->param("attachment_select") ||
+                   ! length $q->param("attachment_select"))) {
                        $form->tmpl_param("attachments-class" => "toggleable");
                }
                else {
@@ -87,6 +88,10 @@ sub formbuilder (@) { #{{{
                # of the temp file that CGI writes the upload to.
                my $tempfile=$q->tmpFileName($filename);
                
+               if (! defined $tempfile) {
+                       error("failed to determine temp filename");
+               }
+
                $filename=IkiWiki::titlepage(
                        IkiWiki::possibly_foolish_untaint(
                                attachment_location($form->field('page')).
@@ -132,7 +137,13 @@ sub formbuilder (@) { #{{{
                else {
                        my $fh=$q->upload('attachment');
                        if (! defined $fh || ! ref $fh) {
-                               error("failed to get filehandle");
+                               # needed by old CGI versions
+                               $fh=$q->param('attachment');
+                               if (! defined $fh || ! ref $fh) {
+                                       # even that doesn't always work,
+                                       # fall back to opening the tempfile
+                                       open($fh, "<", $tempfile) || error("failed to open $tempfile: $!");
+                               }
                        }
                        binmode($fh);
                        writefile($filename, $config{srcdir}, undef, 1, sub {