2007-10-11 16:25:56 +00:00
|
|
|
#!/usr/bin/perl
|
2007-10-11 17:06:08 +00:00
|
|
|
require "include.pl";
|
|
|
|
require "functions.pl";
|
2007-10-10 21:48:12 +00:00
|
|
|
|
|
|
|
CGI::Session->name($session_name);
|
|
|
|
$query = CGI->new(\&hook);
|
|
|
|
$session = new CGI::Session;
|
|
|
|
|
2007-10-11 17:26:39 +00:00
|
|
|
sub hook
|
2007-10-16 19:45:55 +00:00
|
|
|
{hhg
|
2007-10-10 21:48:12 +00:00
|
|
|
#this is going to become an ajax progress bar
|
2007-10-15 00:25:23 +00:00
|
|
|
#alternatively, reloading every N seconds (mozilla doesn't flicker)
|
2007-10-10 21:48:12 +00:00
|
|
|
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 17:26:39 +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;
|
|
|
|
|
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-12 00:34:32 +00:00
|
|
|
my $sth = $dbh->prepare(qq{insert into videos (title, caption, userid, status, timestamp) values ( ?, ?, ?, 0, now())}) or die $dbh->errstr;
|
|
|
|
|
|
|
|
#execute it
|
|
|
|
$sth->execute($query->param("title"), $query->param("caption"), $userid) or die $dbh->errstr;
|
2007-10-11 10:00:38 +00:00
|
|
|
|
2007-10-12 00:34:32 +00:00
|
|
|
#finish query
|
|
|
|
$sth->finish() or die $dbh->errstr;
|
|
|
|
|
2007-10-11 10:57:52 +00:00
|
|
|
#prepare query
|
2007-10-12 00:34:32 +00:00
|
|
|
$sth = $dbh->prepare(qq{select last_insert_id() }) or die $dbh->errstr;
|
2007-10-11 10:57:52 +00:00
|
|
|
|
|
|
|
#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-12 15:50:05 +00:00
|
|
|
open(TEMPFILE, ">$gnutube_root/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-11 17:26:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-10 21:48:12 +00:00
|
|
|
print $session->header();
|
|
|
|
print "nope...";
|
|
|
|
}
|