Calendar Uploader

“; print_r($_FILES); print “
“;

// escape the backslashes
$themeDir = “/themes/thetextilespace/calendars/”;
$icalEventsCache = “/uploads/ical-events-cache/” . “*.ics”;

$wpContentDir = rtrim(dirname(__FILE__), “/plugins/exec-php/includes”);
$target = $wpContentDir. $themeDir . basename($_FILES[‘uploaded’][‘name’]);
$ok=1;

//This is our size condition
if ($uploaded_size > 100000)
{
echo “
Your file is too large.
“;
$ok=0;
}

//Check password
if ($_POST[“password”] <> “fishtank”)
{
echo “
Password invalid
“;
$ok=0;
}

//This is our limit file type condition
if ($_FILES[‘uploaded’][‘type’] <> “text/calendar”)
{
echo “
Only calendar files please

“;
$ok=0;
}

//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo “
Sorry your file was not uploaded due to above errors

“;
}

//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES[‘uploaded’][‘tmp_name’], $target))
{
echo “The file “. basename($_FILES[‘uploaded’][‘name’]). ” (” . basename($_FILES[‘uploaded’][‘size’]). ” bytes) (” . $_FILES[‘uploaded’][‘type’] . “) has been uploaded”;

// Now delete the icalEventsCache
$files = glob($wpContentDir . $icalEventsCache);
print “

Clearing icalEventsCache –

” . $wpContentDir . $icalEventsCache . “

“;print_r($files);print “
“;
foreach($files as $filetodelete) unlink($filetodelete);
}
else
{
echo “Sorry, there was a problem uploading your file.”;
}
}
?>