Hi everyone,
I'm currently building a pilot site for sharing medical education videos which are self-produced (so no copyright/legal issues involved).. And hoping to present it to my faculty in the next few months.
I'm working on the uploading page at the moment and having a few issues. I estimate the videos will be around 10MB in size each, so was creating an ajax-based progress meter during the upload. Uploading is done via a perl/cgi script.
This is the cgi script i'm using which is customised and copy/pasted from various sources so the code is a bit messy.
The problem I have is that there is a large delay before upload starts and the upload speed is very slow (but i do have an 8MB line!). And on rare occasions, I receive an 'Internal Server Error' for no apparent reason.
Would anyone be able to recognise any problems with this script please?
Thank you very much,
Hitesh.
I'm currently building a pilot site for sharing medical education videos which are self-produced (so no copyright/legal issues involved).. And hoping to present it to my faculty in the next few months.
I'm working on the uploading page at the moment and having a few issues. I estimate the videos will be around 10MB in size each, so was creating an ajax-based progress meter during the upload. Uploading is done via a perl/cgi script.
This is the cgi script i'm using which is customised and copy/pasted from various sources so the code is a bit messy.
The problem I have is that there is a large delay before upload starts and the upload speed is very slow (but i do have an 8MB line!). And on rare occasions, I receive an 'Internal Server Error' for no apparent reason.
Would anyone be able to recognise any problems with this script please?
Thank you very much,
Hitesh.
Code:
#!/usr/bin/perl -w
use CGI;
use Fcntl qw(:DEFAULT :flock);
use File::Temp qw/ tempfile tempdir /;
use CGI::Carp qw/fatalsToBrowser/;
my $q = new CGI;
$len = $ENV{'CONTENT_LENGTH'};
my $filename = $q->upload('file');
my $output_file = "../submitted/".$q->param('rand');
my $data_file = "../submitted/".$q->param('rand').".txt";
my ($bytesread, $buffer);
my $numbytes = 4096;
sysopen(FH, $data_file, O_RDWR | O_CREAT) or bye_bye("can't open numfile $monitor_file: $! (Please edit [\$tmp_dir='$tmp_dir'] in header.cgi)");
# autoflush FH
$ofh = select(FH); $| = 1; select ($ofh);
flock(FH, LOCK_EX) or bye_bye("can't write-lock numfile: $!");
seek(FH, 0, 0) or bye_bye("can't rewind numfile : $!");
print FH $len;
close(FH);
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat($filename);
open (DATAFILE, ">", "$data_file") or die "Couldn't open datafile for writing: $!";
print DATAFILE $output_file."\n";
print DATAFILE $size."\n";
print DATAFILE $filename;
close(DATAFILE);
sleep(1);
open (OUTFILE, ">", "$output_file") or die "Couldn't open $output_file for writing: $!";
while ($bytesread = read($filename, $buffer, $numbytes)){
print OUTFILE $buffer;
select(undef, undef, undef,0.35); # sleep for 0.35 of a second.
}
close OUTFILE;
print "Content-type: text/html\n\n";
print "Uploaded!".$size;