DEV Community

CoderLegion
CoderLegion

Posted on • Edited on • Originally published at coderlegion.com

1

File_get_contents('php //input') not working

🎉 Before you dive into this article...

🚀 Check out our vibrant new community at CoderLegion.com!

💡 Share your knowledge, connect with like-minded developers, and grow together.

👉 Click here to join now!

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:

  1. The curl url you used, make sure that url is actually working and

not returning errors.

  1. 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.

  1. 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)

  1. 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.

  1. 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);

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay