user7780894
user7780894

Reputation:

How to get PUT content from HTTP request in PHP

I am trying to declare HTTP PUT variable in php. This is my code:

<?php 
    ${"_" . $_SERVER['REQUEST_METHOD']} = /* What should be here? */;
?>

I tried var_dump($_SERVER) but it does not contain the data sent using ajax request. I am sure there is no problem with $.ajax().

Upvotes: 0

Views: 5452

Answers (1)

Erik Kalkoken
Erik Kalkoken

Reputation: 32697

While there is no official $_PUT variable in PHP, you can create one yourself like this:

$method = $_SERVER['REQUEST_METHOD'];
if ('PUT' === $method) {
    parse_str(file_get_contents('php://input'), $_PUT);
    var_dump($_PUT); //$_PUT contains put fields 
}

Source: https://stackoverflow.com/a/41959141/4379151

Upvotes: 7

Related Questions