-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.pl
40 lines (32 loc) · 1.16 KB
/
upload.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/perl
use CGI;
use CGI::Carp 'fatalsToBrowser';
use HTML::Template;
use File::Basename qw(dirname);
use Cwd qw(abs_path);
use lib dirname(dirname abs_path $0);
use Solfa qw(sf2ly);
use constant TMPDIR => "/var/tmp/nysolfa";
my $q = CGI->new;
$lightweight_fh = $q->upload('file');
# undef may be returned if it's not a valid file handle
if (defined $lightweight_fh) {
# Upgrade the handle to one compatible with IO::Handle:
my $io_handle = $lightweight_fh->handle;
my $generatemidi = $q->param('generatemidi');
my $midiinstrument = $q->param('midiinstrument');
my $generatepdf = $q->param('generatepdf');
my $filename = $q->param('file');
my $savepath = TMPDIR."/$filename";
open (OUTFILE,'>',$savepath);
while ($bytesread = $io_handle->read($buffer,1024)) {
print OUTFILE $buffer;
}
close OUTFILE;
&sf2ly($savepath, $generatemidi, $midiinstrument,$generatepdf);
my $fileprefix = substr($filename,0,-3);
my $result = HTML::Template->new(filename => 'result.tmpl.html');
$result->param(PDFURL => "files/$fileprefix.pdf");
$result->param(MIDIURL => "files/$fileprefix.midi");
print "Content-type: text/html\n\n", $result->output;
}