Skip to content

Instantly share code, notes, and snippets.

@fernandoc1
Last active July 3, 2018 13:38
Show Gist options
  • Select an option

  • Save fernandoc1/b45cd46f17ef5a67457b4529a2fd474b to your computer and use it in GitHub Desktop.

Select an option

Save fernandoc1/b45cd46f17ef5a67457b4529a2fd474b to your computer and use it in GitHub Desktop.
A way to load files using PHP
<?php
$filepath = $_GET["path"];
$type = mime_content_type($filepath);
header('Content-Type: ' . $type);
echo file_get_contents($filepath);
?>
<html>
<body>
<input id="filepathInput" type="text"></input>
<button id="getButton" onclick="getData()">GET</button>
<pre id="outputPre"></pre>
</body>
</html>
<script>
function getData()
{
var path = document.getElementById("filepathInput").value;
fetch("get_file.php?path="+path)
.then(function(response)
{
return response.text();
})
.then(function(text)
{
document.getElementById("outputPre").innerHTML = text;
});
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment