3 # Copyright (C) 2007 LibLime
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
22 # standard or CPAN modules used
27 use C4
::Auth qw
/check_cookie_auth/;
28 use CGI
::Cookie
; # need to check cookies before
29 # having CGI parse the POST request
32 # upload-file.pl must authenticate the user
33 # before processing the POST request,
34 # and quickly bounce if the user is
35 # not authorized. Consequently, unlike
36 # most of the other CGI scripts, upload-file.pl
37 # requires that the session cookie already
40 my %cookies = fetch CGI
::Cookie
;
41 my ($auth_status, $sessionID) = check_cookie_auth
($cookies{'CGISESSID'}->value, { tools
=> '*' });
42 if ($auth_status ne "ok") {
43 $auth_status = 'denied' if $auth_status eq 'failed';
44 send_reply
($auth_status, "");
48 my $uploaded_file = C4
::UploadedFile
->new($sessionID);
49 unless (defined $uploaded_file) {
50 # FIXME - failed to create file for some reason
51 send_reply
('failed', '');
54 $uploaded_file->max_size($ENV{'CONTENT_LENGTH'}); # may not be the file size, exactly
59 $query = new CGI \
&upload_hook
;
60 $uploaded_file->done();
61 send_reply
('done', $uploaded_file->id());
63 # FIXME - if possible, trap signal caused by user cancelling upload
64 # FIXME - something is wrong during cleanup: \t(in cleanup) Can't call method "commit" on unblessed reference at /usr/local/share/perl/5.8.8/CGI/Session/Driver/DBI.pm line 130 during global destruction.
68 my ($file_name, $buffer, $bytes_read, $session) = @_;
69 $uploaded_file->stash(\
$buffer, $bytes_read);
71 $uploaded_file->name($file_name);
77 my ($upload_status, $fileid) = @_;
79 my $reply = CGI
->new("");
80 print $reply->header(-type
=> 'text/html');
81 # response will be sent back as JSON
82 print "{ status: '$upload_status', fileid: '$fileid' }";