function doDownloadAndExit()
{
    $fileMetadata = schematicRetrieval::getMetadata($_GET['downloadId']);
    $fileContents = schematicRetrieval::getFile($_GET['downloadId']);
    $fileSize = strval(strlen($fileContents));
    $fileName = $fileMetadata['fileName'];
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename=' . $fileName . '.schematic');
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . $fileSize);
    echo $fileContents;
    exit;
}
<?php

/*
 * JavaScript Redstone Simulator
 * Copyright (C) 2012  Jonathan Lydall (Email: jonathan.lydall@gmail.com)
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. 
 * 
 */
include 'includes/class_schematicRetrieval.php';
$recordId = isset($_GET['id']) ? $_GET['id'] : 0;
echo json_encode(schematicRetrieval::getMetadata($recordId));
 public static function save()
 {
     self::init();
     self::checkPost('title');
     self::checkPost('filename');
     self::checkPost('description');
     self::checkPost('id');
     self::checkPost('derivedFromId');
     self::checkPost('schematicData');
     self::checkPost('isCompressed');
     $isCompressed = $_POST['isCompressed'] == "true";
     if ($isCompressed && !self::validateCompression()) {
         return array('error' => true, 'compressionError' => true);
     }
     if (!$isCompressed) {
         self::onUncompressed();
     }
     if (!self::isLoggedOn()) {
         $error = true;
         $errorMessages['general'] = "Not logged in.";
         return array('error' => true, 'errorMessages' => array("general" => "Not logged in."));
     }
     $errorMessages = self::getErrors();
     if ($errorMessages['general'] != "") {
         return array('error' => true, 'errorMessages' => $errorMessages);
     }
     // If we are recieving a new schematic, the posted schematic ID is -1
     if ($_POST['id'] == -1) {
         $schematicId = self::insertIntoDatabase();
         $successMessage = 'New record inserted.';
     } else {
         $schematicId = self::updateIntoDatabase();
         $successMessage = 'Record updated.';
     }
     return array('error' => false, 'successMessage' => $successMessage, "metaData" => schematicRetrieval::getMetadata($schematicId));
 }
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. 
 * 
 */
include 'includes/class_schematicRetrieval.php';
$id = isset($_GET["id"]) ? $_GET["id"] : -1;
$fileMetadata = schematicRetrieval::getMetadata($id);
if ($fileMetadata['error']) {
    $error = true;
    $errorText = $fileMetadata['errorDescription'];
} else {
    $error = false;
    $fileContents = schematicRetrieval::getFile($id);
    $fileSize = strval(strlen($fileContents));
    $fileName = $fileMetadata['fileName'];
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename=' . $fileName . '.schematic');
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . $fileSize);
    echo $fileContents;
}
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. 
 * 
 */
ob_start("ob_gzhandler");
//HTTP compression
include 'php/includes/class_userManager.php';
include 'php/includes/class_localization.php';
include 'php/includes/class_schematicRetrieval.php';
include 'php/includes/googleAnalyticsScriptTagGenerator.php';
include 'php/socialButtons.php';
$runningOnLive = !(strpos($_SERVER['HTTP_HOST'], 'mordritch.com') === false);
$language = "en_US";
//TODO: Have this autodetected from cookie or otherwise the request headers
$sessionData = json_encode(userManager::switchTask_standalone('process_getCurrentSessionData'));
$schematicIdToOpen = isset($_GET["id"]) ? json_encode(intval($_GET["id"])) : "null";
$schematicMetadata = schematicRetrieval::getMetadata($schematicIdToOpen);
$schematicMetadataEncoded = json_encode($schematicMetadata);
function generateScriptTags($prependedWhitespace = '')
{
    global $runningOnLive;
    global $language;
    $returnString = '';
    if ($runningOnLive) {
        $buildNumber = intval(file_get_contents('release/mc_rss-min.js_build#'));
        $returnString = $prependedWhitespace . '<script type="text/javascript" src="release/mc_rss-min.js?b=' . $buildNumber . '"></script>' . PHP_EOL;
        $languageBuildNumber = intval(file_get_contents('release/locals/' . $language . '.js_build#'));
        $returnString .= $prependedWhitespace . '<script type="text/javascript" src="release/locals/' . $language . '.js?b=' . $languageBuildNumber . '"></script>' . PHP_EOL;
    } else {
        $returnString .= $prependedWhitespace . '<!-- BEGIN GENERATED SCRIPT TAGS -->' . PHP_EOL;
        $fileList = file('src/_fileList.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
        for ($i = 0; $i < count($fileList); $i++) {