Fix upload function in Apache2.x, the bug is descripted in
[irspy-moved-to-github.git] / web / htdocs / details / upload.mc
1 %# $Id: upload.mc,v 1.3 2009-04-16 18:09:44 wosch Exp $
2 <%args>
3 $filename => undef
4 </%args>
5 % if (!defined $filename) {
6    <p>
7     Please note that this form expects a
8     <a href="http://explain.z3950.org/"
9         >ZeeRex record</a>
10     only, not an entire
11     <a href="http://www.loc.gov/standards/sru/explain/"
12         >SRU explainResponse</a>.
13    <p>
14    <form method="post" action=""
15             enctype="multipart/form-data">
16     <p>
17      ZeeRex file to upload:
18      <input type="file" name="filename" size="50"/>
19      <br/>
20      <input type="submit" name="_submit" value="Submit"/>
21     </p>
22    </form>
23 % return;
24 % }
25 <%perl>
26
27 my $fin;
28
29 # Apache2.0 
30 if ($r->isa('Apache2::RequestRec')) {
31     require Apache2::Request;
32     require Apache2::Upload;
33     my $req = new Apache2::Request($r);
34     my $upload = $req->upload('filename');
35     $fin = $upload->fh();
36
37
38 # Apache 1.3
39 else {
40     $fin = $r->upload()->fh();
41 }
42
43 if (!defined $fin) {
44     $m->comp("/details/error.mc", msg => "Upload cancelled");
45     return;
46 }
47
48 my $xml = join("", <$fin>);
49 my $xc = irspy_xpath_context($xml);
50 my $id = irspy_record2identifier($xc);
51 my $conn = new ZOOM::Connection("localhost:8018/IR-Explain---1", 0,
52                                 user => "admin", password => "fruitbat",
53                                 elementSetName => "zeerex");
54 ZOOM::IRSpy::_really_rewrite_record($conn, $xc->getContextNode());
55 </%perl>
56      <p>
57       Upload OK.
58      </p>
59      <p>
60       Proceed to
61       <a href="<% xml_encode("/full.html?id=" . uri_escape($id))
62         %>">the new record</a>.
63      </p>