Skip to content

Instantly share code, notes, and snippets.

@greyaperez
Created November 27, 2013 19:37
Show Gist options
  • Save greyaperez/7681840 to your computer and use it in GitHub Desktop.
Save greyaperez/7681840 to your computer and use it in GitHub Desktop.
Just point your REST call to this file and it will store it to a file. Just change $file to whatever file you would like, currently set to request.json. Also remember to chmod that file so it's writable.
<?php
header("Access-Control-Allow-Orgin: *");
header("Access-Control-Allow-Methods: *");
header("Content-Type: application/json");
$requestData = '';
if(isset($HTTP_RAW_POST_DATA) && strlen($HTTP_RAW_POST_DATA) > 0){
// POST
$requestData = file_get_contents('php://input');
if(strlen($requestData) < 0){
$requestData = $HTTP_RAW_POST_DATA;
}
} elseif ($_SERVER['REQUEST_METHOD'] === 'GET') {
// GET
$requestData = $_REQUEST;
} elseif ($_SERVER['REQUEST_METHOD'] === 'PUT') {
// PUT
$requestData = file_get_contents("php://input");
} elseif ($_SERVER['REQUEST_METHOD'] === 'DELETE'){
$requestData = 'DELETE CALLED';
}
$file = './request.json';
file_put_contents($file, $requestData);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment