PHP has $_get,$_post, but no $_put, so if you need to use it, then you have to simulate it yourself:
Copy CodeThe code is as follows:
$_put = Array ();
if (' PUT ' = = $_server[' Request_method ')} {
Parse_str (file_get_contents (' Php://input '), $_put);
}
The data obtained through Php://input is raw, so we need to parse it with PARSE_STR.
However, it is necessary to note that when the form is enctype= "Multipart/form-data" type (that is, the type of upload file), this method is invalid (this time the Php://input is empty), Once the PHP discovery request Content-type is multipart/form-data, will be unconditional for you to process the form data, and then save to $_files, at this time can not get raw data, can only use some partial gate method, to Apache, for example, Modify httpd.conf (to use the Requestheader syntax, first activate the header module):
Copy CodeThe code is as follows:
Requestheader Set Content-type Foobar
By resetting the Content-type request header to Foobar (as long as it is not multipart/form-data), at this time the Php://input has data, but the original $_files data does not exist, so basically only the meaning of the demonstration, If you want to get raw data, you can only build on your own data, there are similar implementations in pear: Http_request2_multipartbody.
Browsers generally only allow the use of the Get/post method, although you can send the Put method through JS, but also to write code, relatively speaking, the use of the command Line Curl command is much more convenient, in the development of testing is very useful, so learning is still necessary:
Curl-x PUT http://www.domain.com/demo.php-d "id=1"-D "title=a"
This will send the ID by the Put method, the title data, the test demo.php code is similar to the above php://input, do not elaborate.
Add: Note the Always_populate_raw_post_data settings in php.ini.
http://www.bkjia.com/PHPjc/321517.html www.bkjia.com true http://www.bkjia.com/PHPjc/321517.html techarticle PHP has $_get,$_post, but there is no $_put, so if you need to use it, you have to simulate it yourself: Copy the code as follows: $_put = Array (); if (' PUT ' = = $_ser ...