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
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #use warnings; FIXME - Bug 2505
23 # standard or CPAN modules used
28 use C4
::Auth qw
/check_cookie_auth/;
29 use CGI
::Cookie
; # need to check cookies before
30 # having CGI parse the POST request
33 # upload-file.pl must authenticate the user
34 # before processing the POST request,
35 # and quickly bounce if the user is
36 # not authorized. Consequently, unlike
37 # most of the other CGI scripts, upload-file.pl
38 # requires that the session cookie already
41 my %cookies = fetch CGI
::Cookie
;
42 my ($auth_status, $sessionID) = check_cookie_auth
($cookies{'CGISESSID'}->value, { tools
=> '*' });
43 if ($auth_status ne "ok") {
44 $auth_status = 'denied' if $auth_status eq 'failed';
45 send_reply
($auth_status, "");
49 my $uploaded_file = C4
::UploadedFile
->new($sessionID);
50 unless (defined $uploaded_file) {
51 # FIXME - failed to create file for some reason
52 send_reply
('failed', '');
55 $uploaded_file->max_size($ENV{'CONTENT_LENGTH'}); # may not be the file size, exactly
60 $query = new CGI \
&upload_hook
;
61 $uploaded_file->done();
62 send_reply
('done', $uploaded_file->id());
64 # FIXME - if possible, trap signal caused by user cancelling upload
65 # 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.
69 my ($file_name, $buffer, $bytes_read, $session) = @_;
70 $uploaded_file->stash(\
$buffer, $bytes_read);
72 $uploaded_file->name($file_name);
78 my ($upload_status, $fileid) = @_;
80 my $reply = CGI
->new("");
81 print $reply->header(-type
=> 'text/html');
82 # response will be sent back as JSON
83 print "{ status: '$upload_status', fileid: '$fileid' }";