Lines 26-31
Koha::Upload - Facilitate file uploads (temporary and permanent)
Link Here
|
26 |
=head1 SYNOPSIS |
26 |
=head1 SYNOPSIS |
27 |
|
27 |
|
28 |
use Koha::Upload; |
28 |
use Koha::Upload; |
|
|
29 |
use Koha::UploadedFile; |
29 |
use Koha::UploadedFiles; |
30 |
use Koha::UploadedFiles; |
30 |
|
31 |
|
31 |
# add an upload (see tools/upload-file.pl) |
32 |
# add an upload (see tools/upload-file.pl) |
Lines 34-48
Koha::Upload - Facilitate file uploads (temporary and permanent)
Link Here
|
34 |
my $cgi = $upload->cgi; |
35 |
my $cgi = $upload->cgi; |
35 |
# Do something with $upload->count, $upload->result or $upload->err |
36 |
# Do something with $upload->count, $upload->result or $upload->err |
36 |
|
37 |
|
37 |
# get some upload records (in staff) |
38 |
# get some upload records (in staff) via Koha::UploadedFiles |
38 |
my @uploads1 = Koha::UploadedFiles->search({ filename => $name }); |
39 |
my @uploads1 = Koha::UploadedFiles->search({ filename => $name }); |
39 |
my @uploads2 = Koha::UploadedFiles->search_term({ term => $term }); |
40 |
my @uploads2 = Koha::UploadedFiles->search_term({ term => $term }); |
40 |
|
41 |
|
41 |
# staff download |
42 |
# staff download (via Koha::UploadedFile[s]) |
42 |
my $rec = Koha::UploadedFiles->find( $id ); |
43 |
my $rec = Koha::UploadedFiles->find( $id ); |
43 |
my $fh = $rec->file_handle; |
44 |
my $fh = $rec->file_handle; |
44 |
my @hdr = Koha::Upload->httpheaders( $rec->filename ); |
45 |
print Encode::encode_utf8( $input->header( $rec->httpheaders ) ); |
45 |
print Encode::encode_utf8( $input->header( @hdr ) ); |
|
|
46 |
while( <$fh> ) { print $_; } |
46 |
while( <$fh> ) { print $_; } |
47 |
$fh->close; |
47 |
$fh->close; |
48 |
|
48 |
|
Lines 56-63
Koha::Upload - Facilitate file uploads (temporary and permanent)
Link Here
|
56 |
The module has been revised to use Koha::Object[s]; the delete method |
56 |
The module has been revised to use Koha::Object[s]; the delete method |
57 |
has been moved to Koha::UploadedFile[s], as well as the get method. |
57 |
has been moved to Koha::UploadedFile[s], as well as the get method. |
58 |
|
58 |
|
59 |
=head1 INSTANCE METHODS |
|
|
60 |
|
61 |
=cut |
59 |
=cut |
62 |
|
60 |
|
63 |
use constant KOHA_UPLOAD => 'koha_upload'; |
61 |
use constant KOHA_UPLOAD => 'koha_upload'; |
Lines 80-85
use Koha::UploadedFiles;
Link Here
|
80 |
|
78 |
|
81 |
__PACKAGE__->mk_ro_accessors( qw|| ); |
79 |
__PACKAGE__->mk_ro_accessors( qw|| ); |
82 |
|
80 |
|
|
|
81 |
=head1 INSTANCE METHODS |
82 |
|
83 |
=head2 new |
83 |
=head2 new |
84 |
|
84 |
|
85 |
Returns new object based on Class::Accessor. |
85 |
Returns new object based on Class::Accessor. |
Lines 160-192
sub err {
Link Here
|
160 |
|
160 |
|
161 |
=head1 CLASS METHODS |
161 |
=head1 CLASS METHODS |
162 |
|
162 |
|
163 |
=head2 getCategories |
|
|
164 |
|
165 |
getCategories returns a list of upload category codes and names |
166 |
|
167 |
=cut |
168 |
|
169 |
sub getCategories { |
170 |
my ( $class ) = @_; |
171 |
my $cats = C4::Koha::GetAuthorisedValues('UPLOAD'); |
172 |
[ map {{ code => $_->{authorised_value}, name => $_->{lib} }} @$cats ]; |
173 |
} |
174 |
|
175 |
=head2 httpheaders |
176 |
|
177 |
httpheaders returns http headers for a retrievable upload |
178 |
Will be extended by report 14282 |
179 |
|
180 |
=cut |
181 |
|
182 |
sub httpheaders { |
183 |
my ( $class, $name ) = @_; |
184 |
return ( |
185 |
'-type' => 'application/octet-stream', |
186 |
'-attachment' => $name, |
187 |
); |
188 |
} |
189 |
|
190 |
=head2 allows_add_by |
163 |
=head2 allows_add_by |
191 |
|
164 |
|
192 |
allows_add_by checks if $userid has permission to add uploaded files |
165 |
allows_add_by checks if $userid has permission to add uploaded files |