<?php
// processes the dsp_upload.php form
$errors = array();
$uploadfile = $vsf->config->misc->datadir . "/" . $_POST['userfile'];
$tmpuploadfile = $vsf->config->misc->datadir . "/tmp_" . $_POST['userfile'];
if (! $_POST['userfile']) {
array_push($errors,"No file passed back in, form called incorrectly?");
}
if (! $errors && file_exists($uploadfile) ) {
array_push($errors,"A file with that name already exists (" . $_POST['userfile'] . ")");
}
// if the tmp_ file no longer exists, the user probably hit 'refresh' and resubmitted the form
if (! $errors && ! file_exists($tmpuploadfile) ) {
array_push($errors,"Could not find file from previous step - Maybe you hit refresh?");
}
// before we try to move the file from the tmp name to the correct name, make sure we have
// database connectivity
if (! $errors && ! $vsf->connect() ) {
array_push($errors,"Could not connect to the database! Error was: " . $vsf->mysql_error);
}
// now try to move the tmp file to the correct filename
if (! $errors && ! @rename($tmpuploadfile,$uploadfile) ) {
array_push($errors,"Could not copy tmp file to permanent file in datadir.");
}
// if any errors, redisplay the form.
if ($errors) {
include('dsp_upload2.php');
}
else {
// else, load file into the database
$query = "INSERT INTO episodes (title, subtitle, keywords, author, description, pubdate, size, duration, filename) ";
$query .= "VALUES (";
$query .= "'" . mysql_real_escape_string($_POST['title']) . "', " .
"'" . mysql_real_escape_string($_POST['subtitle']) . "', " .
"'" . mysql_real_escape_string($_POST['keywords']) . "', " .
"'" . mysql_real_escape_string($_POST['author']) . "', " .
"'" . mysql_real_escape_string($_POST['description']) . "', " .
"FROM_UNIXTIME('" . strtotime(mysql_real_escape_string($_POST['pubdate'])) . "'), " .
"'" . mysql_real_escape_string($_POST['size']) . "', " .
"'" . mysql_real_escape_string($_POST['duration']) . "', " .
"'" . mysql_real_escape_string(basename($uploadfile)) . "')";
if ( ! mysql_query($query) ) {
// query failed, so we should delete the file we copied into the datadir
unlink($uploadfile);
exit("Query failed! - $query<Br>" . mysql_error());
}
print "<p style='color: green'>Episode <b>" . $_POST['title'] . "</b> was added.</p>\n";
// now regenerate the RSS feed file
include('act_genrssfile.php');
// blank out the form fields
unset($_POST);
// display the upload new episode form
include('dsp_upload.php');
}
?>