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-10 21:48:12 +00:00
|
|
|
#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 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-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-11 17:26:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-10 21:48:12 +00:00
|
|
|
print $session->header();
|
|
|
|
print "nope...";
|
|
|
|
}
|