@@ -, +, @@ If possible, include some special chars in the filename. --- .../bootstrap/en/modules/opac-retrieve-file.tt | 6 ++++ opac/opac-retrieve-file.pl | 36 ++++++++++++++------ tools/upload.pl | 2 +- 3 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-retrieve-file.tt --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-retrieve-file.tt +++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-retrieve-file.tt @@ -0,0 +1,6 @@ +[%# This template is called only for a very simple error message %] + + +Your search [% IF hash %]for [% hash %][% END %] was not successful. + + --- a/opac/opac-retrieve-file.pl +++ a/opac/opac-retrieve-file.pl @@ -19,19 +19,33 @@ use Modern::Perl; use CGI; +use Encode; +use C4::Auth; use C4::Context; -use C4::UploadedFiles; +use C4::Output; +use Koha::Upload; -my $input = new CGI; +my $input = CGI::->new; +my $hash = $input->param('id'); # historically called id (used in URLs?) -my $id = $input->param('id'); -my $file = C4::UploadedFiles::GetUploadedFile($id); -exit 1 if !$file || !-f $file->{filepath}; - -open my $fh, '<', $file->{filepath} or die "Can't open file: $!"; -print $input->header( C4::UploadedFiles::httpheaders( $file->{filename} )); -while(<$fh>) { - print $_; +my $upl = Koha::Upload->new({ public => 1 }); +my $rec = $upl->get({ hashvalue => $hash, filehandle => 1 }); +my $fh = $rec->{fh}; +if( !$rec || !$fh ) { + my ( $template, $user, $cookie ) = get_template_and_user({ + query => $input, + template_name => 'opac-retrieve-file.tt', + type => 'opac', + authnotrequired => 1, + }); + $template->param( hash => $hash ); + output_html_with_http_headers $input, $cookie, $template->output; +} else { + my @hdr = $upl->httpheaders( $rec->{name} ); + print Encode::encode_utf8( $input->header( @hdr ) ); + while( <$fh> ) { + print $_; + } + $fh->close; } -close $fh; --- a/tools/upload.pl +++ a/tools/upload.pl @@ -89,7 +89,7 @@ if( $op eq 'new' ) { output_html_with_http_headers $input, $cookie, $template->output; } else { my @hdr = $upl->httpheaders( $rec->{name} ); - print $input->header( @hdr ); + print Encode::encode_utf8( $input->header( @hdr ) ); while( <$fh> ) { print $_; } --