Lines 19-37
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
use CGI; |
21 |
use CGI; |
|
|
22 |
use Encode; |
22 |
|
23 |
|
|
|
24 |
use C4::Auth; |
23 |
use C4::Context; |
25 |
use C4::Context; |
24 |
use C4::UploadedFiles; |
26 |
use C4::Output; |
|
|
27 |
use Koha::Upload; |
25 |
|
28 |
|
26 |
my $input = new CGI; |
29 |
my $input = CGI::->new; |
|
|
30 |
my $hash = $input->param('id'); # historically called id (used in URLs?) |
27 |
|
31 |
|
28 |
my $id = $input->param('id'); |
32 |
my $upl = Koha::Upload->new({ public => 1 }); |
29 |
my $file = C4::UploadedFiles::GetUploadedFile($id); |
33 |
my $rec = $upl->get({ hashvalue => $hash, filehandle => 1 }); |
30 |
exit 1 if !$file || !-f $file->{filepath}; |
34 |
my $fh = $rec->{fh}; |
31 |
|
35 |
if( !$rec || !$fh ) { |
32 |
open my $fh, '<', $file->{filepath} or die "Can't open file: $!"; |
36 |
my ( $template, $user, $cookie ) = get_template_and_user({ |
33 |
print $input->header( C4::UploadedFiles::httpheaders( $file->{filename} )); |
37 |
query => $input, |
34 |
while(<$fh>) { |
38 |
template_name => 'opac-retrieve-file.tt', |
35 |
print $_; |
39 |
type => 'opac', |
|
|
40 |
authnotrequired => 1, |
41 |
}); |
42 |
$template->param( hash => $hash ); |
43 |
output_html_with_http_headers $input, $cookie, $template->output; |
44 |
} else { |
45 |
my @hdr = $upl->httpheaders( $rec->{name} ); |
46 |
print Encode::encode_utf8( $input->header( @hdr ) ); |
47 |
while( <$fh> ) { |
48 |
print $_; |
49 |
} |
50 |
$fh->close; |
36 |
} |
51 |
} |
37 |
close $fh; |
|
|