MARC21slim2OPACResultsFFZG.xsl
[koha.git] / tools / upload-file.pl
index 6b1fabb..b705f5c 100755 (executable)
@@ -18,6 +18,7 @@
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 use strict;
+#use warnings; FIXME - Bug 2505
 
 # standard or CPAN modules used
 use IO::File;
@@ -45,7 +46,7 @@ if ($auth_status ne "ok") {
     exit 0;
 }
 
-my $uploaded_file = C4::UploadedFile->new($sessionID);
+our $uploaded_file = C4::UploadedFile->new($sessionID);
 unless (defined $uploaded_file) {
     # FIXME - failed to create file for some reason
     send_reply('failed', '');
@@ -53,8 +54,6 @@ unless (defined $uploaded_file) {
 }
 $uploaded_file->max_size($ENV{'CONTENT_LENGTH'}); # may not be the file size, exactly
 
-my $first_chunk = 1;
-
 my $query;
 $query = new CGI \&upload_hook;
 $uploaded_file->done();
@@ -67,9 +66,8 @@ exit 0;
 sub upload_hook {
     my ($file_name, $buffer, $bytes_read, $session) = @_;
     $uploaded_file->stash(\$buffer, $bytes_read);
-    if ($first_chunk) {
+    if ( ! $uploaded_file->name && $file_name ) { # save name on first chunk
         $uploaded_file->name($file_name);
-        $first_chunk = 0;
     }
 }
 
@@ -79,5 +77,5 @@ sub send_reply {
     my $reply = CGI->new("");
     print $reply->header(-type => 'text/html');
     # response will be sent back as JSON
-    print "{ status: '$upload_status', fileid: '$fileid' }";
+    print '{"status":"' . $upload_status . '","fileid":"' . $fileid . '"}';
 }