Problem:
I am unable to understand this problem ..
Please suggest me a better solution to solve it ..File_get_contents('php //input') not working
Solution:
First off, I was able to run this code and it worked fine:
--Terminal---------
//I ran this curl request against my own php file:
curl -i -X PUT -d '{"address":"Sunset Boulevard"}' http://localhost/test.php
--PHP--------------
//get the data
$json = file_get_contents("php://input");
//convert the string of data to an array
$data = json_decode($json, true);
//output the array in the response of the curl request
print_r($data);
If that doesn't work, check the console for errors and your php settings:
- The curl url you used, make sure that url is actually working and
not returning errors.
- open up another terminal / console window and run tail -f
/path/to/the/php/log/file so you can actually see the output of
these php calls.
- often people get this error: file_get_contents(file://input): failed
to open stream: no suitable wrapper could be found which can
indicate either a typo of the "file://input" string or the fact that allow_url_fopen is disabled in php (see #5 if unsure)
- make sure your code is correct, and by that I mean make sure you're
not typing in incorrect arguments and things... stuff that doesn't
necessarily get underlined in netbeans.
- remember, file_get_contents only works when allow_url_fopen is set
to true in your PHP settings. thats something that is set in
php.ini, but you can also change settings at run time by writing
something along the lines of the following code before the other
code:
ini_set("allow_url_fopen", true);
Top comments (0)