X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/f156308aef6fc025237b2d021eea826feea4ce80..2e5785907d6bca9119b1ac0bba31b2260e357613:/IkiWiki/Plugin/attachment.pm diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm index 90e0f0f0b..84bf64390 100644 --- a/IkiWiki/Plugin/attachment.pm +++ b/IkiWiki/Plugin/attachment.pm @@ -21,6 +21,8 @@ sub formbuilder_setup (@) { #{{{ my $q=$params{cgi}; if (defined $form->field("do") && $form->field("do") eq "edit") { + # Add attachment field, set type to multipart. + $form->enctype(&CGI::MULTIPART); $form->field(name => 'attachment', type => 'file'); # These buttons are not put in the usual place, so # are not added to the normal formbuilder button list. @@ -88,6 +90,10 @@ sub formbuilder (@) { #{{{ # 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"); + } + $filename=IkiWiki::titlepage( IkiWiki::possibly_foolish_untaint( attachment_location($form->field('page')). @@ -133,7 +139,14 @@ 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 + $fh=undef; + open($fh, "<", $tempfile) || error("failed to open $tempfile: $!"); + } } binmode($fh); writefile($filename, $config{srcdir}, undef, 1, sub {