+ json_response($q, $form, $dest."/".$filename, stored_msg());
+}
+
+# Save all stored attachments for a page.
+sub attachments_save {
+ my $form=shift;
+ my $session=shift;
+
+ # Move attachments out of holding directory.
+ my @attachments;
+ my $dir=attachment_holding_location(scalar $form->field('page'));
+ foreach my $filename (glob("$dir/*")) {
+ $filename=Encode::decode_utf8($filename);
+ next unless -f $filename;
+ my $destdir=$config{srcdir}."/".
+ linkpage(IkiWiki::possibly_foolish_untaint(
+ attachment_location(scalar $form->field('page'))));
+ my $destfile=IkiWiki::basename($filename);
+ my $dest=$destdir.$destfile;
+ unlink($dest);
+ IkiWiki::prep_writefile($destfile, $destdir);
+ rename($filename, $dest);
+ push @attachments, $dest;
+ }
+ return unless @attachments;
+ require IkiWiki::Render;
+ IkiWiki::prune($dir, $config{wikistatedir}."/attachments");
+
+ # Check the attachments in and trigger a wiki refresh.