2007-10-10 21:48:12 +00:00
|
|
|
require "/var/www/perl/include.pl";
|
|
|
|
require "/var/www/perl/functions.pl";
|
|
|
|
|
|
|
|
CGI::Session->name($session_name);
|
|
|
|
$query = CGI->new(\&hook);
|
|
|
|
$session = new CGI::Session;
|
|
|
|
|
|
|
|
sub hook {
|
|
|
|
#this is going to become an ajax progress bar
|
|
|
|
my ($filename, $buffer, $bytes_read, $data) = @_;
|
2007-10-11 10:57:52 +00:00
|
|
|
#print $ENV{'CONTENT_LENGTH'};
|
|
|
|
#print sha256_hex($buffer);
|
2007-10-10 21:48:12 +00:00
|
|
|
#open(TEMP, ">>/var/www/perl/videos/temp.temp") or die "cannot open";
|
2007-10-11 10:57:52 +00:00
|
|
|
#print "Read $bytes_read bytes of $filename\n";
|
2007-10-10 21:48:12 +00:00
|
|
|
#close TEMP;
|
|
|
|
}
|
|
|
|
|
2007-10-11 10:57:52 +00:00
|
|
|
my $userid = get_userid_from_sid($session->id);
|
2007-10-10 21:48:12 +00:00
|
|
|
|
2007-10-11 10:57:52 +00:00
|
|
|
if($userid) {
|
2007-10-11 10:00:38 +00:00
|
|
|
#connect to db
|
|
|
|
my $dbh = DBI->connect("DBI:mysql:$database:$host", $dbuser, $dbpass) or die $dbh->errstr;
|
|
|
|
|
|
|
|
#save POST data in local variables
|
|
|
|
my $title = $query->param("title");
|
2007-10-11 14:59:55 +00:00
|
|
|
my $caption = $query->param("caption");
|
2007-10-11 10:00:38 +00:00
|
|
|
|
2007-10-11 10:57:52 +00:00
|
|
|
#video status:
|
2007-10-11 14:59:55 +00:00
|
|
|
# 0 - new entry - nothing done yet
|
|
|
|
# 1 - successfully uploaded
|
|
|
|
# 2 - successfully converted
|
|
|
|
# 3 - error: was not a valid video/format
|
|
|
|
# 4 - error: video is a duplicate
|
2007-10-11 10:00:38 +00:00
|
|
|
#do query
|
2007-10-11 14:59:55 +00:00
|
|
|
$dbh->do(qq{insert into videos (title, caption, userid, status) values ('$title', '$caption', '$userid', 0)}) or die $dbh->errstr;
|
2007-10-11 10:00:38 +00:00
|
|
|
|
2007-10-11 10:57:52 +00:00
|
|
|
#prepare query
|
|
|
|
my $sth = $dbh->prepare(qq{select last_insert_id() }) or die $dbh->errstr;
|
|
|
|
|
|
|
|
#execute it
|
|
|
|
$sth->execute() or die $dbh->errstr;
|
|
|
|
|
|
|
|
#save the resulting username
|
|
|
|
my ($id) = $sth->fetchrow_array() or die $dbh->errstr;
|
|
|
|
|
|
|
|
#finish query
|
|
|
|
$sth->finish() or die $dbh->errstr;
|
|
|
|
|
|
|
|
#save uploaded file into temppath
|
2007-10-10 21:48:12 +00:00
|
|
|
$upload_filehandle = $query->upload("file");
|
2007-10-11 10:57:52 +00:00
|
|
|
open(TEMPFILE, ">/var/www/perl/tmp/$id") or die "cannot open";
|
2007-10-10 21:48:12 +00:00
|
|
|
while ( <$upload_filehandle> )
|
|
|
|
{
|
2007-10-11 10:57:52 +00:00
|
|
|
print TEMPFILE;
|
2007-10-10 21:48:12 +00:00
|
|
|
}
|
2007-10-11 10:57:52 +00:00
|
|
|
close TEMPFILE;
|
2007-10-11 10:00:38 +00:00
|
|
|
|
2007-10-11 10:57:52 +00:00
|
|
|
print $session->header();
|
|
|
|
print "passt";
|
|
|
|
print $id;
|
2007-10-11 10:00:38 +00:00
|
|
|
|
|
|
|
#disconnect db
|
|
|
|
$dbh->disconnect() or die $dbh->errstr;
|
2007-10-10 21:48:12 +00:00
|
|
|
} else {
|
|
|
|
print $session->header();
|
|
|
|
print "nope...";
|
|
|
|
}
|