Skip to content

Instantly share code, notes, and snippets.

@mnemocron
Created July 13, 2018 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mnemocron/1df8a7e138845eda4b825935bb4826bc to your computer and use it in GitHub Desktop.
Save mnemocron/1df8a7e138845eda4b825935bb4826bc to your computer and use it in GitHub Desktop.
returns json from a json file.
<?php
header('Content-type: application/json');
$filename = $_GET['f'];
$json_path = './resources/' . $filename;
if (file_exists($json_path) && strcmp(pathinfo($filename, PATHINFO_EXTENSION), 'json') ==0 ) {
$myfile = fopen($json_path, 'r') or die('Unable to open file!');
$jsonstr = fread($myfile, filesize($json_path));
fclose($myfile);
echo $jsonstr;
} else {
echo json_encode(array('status' => 'error'));
}
?>
@mnemocron
Copy link
Author

api.foo.com/file2json.php?f=file.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment