Skip to content

Instantly share code, notes, and snippets.

@s-zeid
Created November 1, 2015 09:32
Show Gist options
  • Save s-zeid/72d9986fd162d2f532f7 to your computer and use it in GitHub Desktop.
Save s-zeid/72d9986fd162d2f532f7 to your computer and use it in GitHub Desktop.
allow Minecraft Overviewer output in a custom directory to be accessed from another directory within the same document root
<?php
$base = "out";
$files = [
"index.html" => function($s) use ($base) {
$s = str_replace("<head>", "<head>\n\n<base href=\"$base/\" />", $s);
$s = str_replace("\"overviewer.js\"", "\"../?overviewer.js\"", $s);
return $s;
},
"overviewer.js" => function($s) {
$s = str_replace("window.location.replace(newHash)",
"window.location.hash = newHash",
$s);
return $s;
},
];
$default_file = "index.html";
//////////////////////////////////////////////////////////////////////////
$file = (!empty($_SERVER["QUERY_STRING"]))
? $_SERVER["QUERY_STRING"]
: $default_file;
$path = (isset($files[$file])) ? "$base".DIRECTORY_SEPARATOR."$file" : "";
if (!is_file($path))
exit("<h1>404 Not Found</h1>");
$mimes = [
".js" => "application/javascript",
];
$mime = "";
foreach ($mimes as $ext => $value) {
if (strtolower(substr($file, strlen($file) - strlen($ext))) === $ext) {
$mime = $value;
break;
}
}
if (empty($mime))
$mime = trim(exec("file --brief --mime-type ".escapeshellarg($path)));
header("Content-Type: $mime");
echo $files[$file](file_get_contents($path));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment