Koha::Upload - Facilitate file uploads (temporary and permanent)
use Koha::Upload; # add an upload (see tools/upload-file.pl) # the public flag allows retrieval via OPAC my $upload = Koha::Upload->new( public => 1, category => 'A' ); my $cgi = $upload->cgi; # Do something with $upload->count, $upload->result or $upload->err # get some upload records (in staff) # Note: use the public flag for OPAC my @uploads = Koha::Upload->new->get( term => $term ); $template->param( uploads => \@uploads ); # staff download my $rec = Koha::Upload->new->get({ id => $id, filehandle => 1 }); my $fh = $rec->{fh}; my @hdr = Koha::Upload->httpheaders( $rec->{name} ); print Encode::encode_utf8( $input->header( @hdr ) ); while( <$fh> ) { print $_; } $fh->close; # delete an upload my ( $fn ) = Koha::Upload->new->delete({ id => $id });
This module is a refactored version of C4::UploadedFile but adds on top of that the new functions from report 6874 (Upload plugin in editor). That report added module UploadedFiles.pm. This module contains the functionality of both.
Returns new object based on Class::Accessor. Use tmp or temp flag for temporary storage. Use public flag to mark uploads as available in OPAC. The category parameter is only useful for permanent storage.
Returns CGI object. The CGI hook is used to store the uploaded files.
Returns number of uploaded files without errors
Returns a string of id's for each successful upload separated by commas.
Returns hash with errors in format { file => err, ... } Undefined if there are no errors.
Returns arrayref of uploaded records (hash) or one uploaded record. You can pass id => $id or hashvalue => $hash or term => $term. Optional parameter filehandle => 1 returns you a filehandle too.
Returns array of deleted filenames or undef. Since it now only accepts id as parameter, you should not expect more than one filename.
getCategories returns a list of upload category codes and names
httpheaders returns http headers for a retrievable upload Will be extended by report 14282
allows_add_by checks if $userid has permission to add uploaded files
Koha Development Team Larger parts from Galen Charlton, Julian Maurice and Marcel de Rooy