/    Sign up×
Community /Pin to ProfileBookmark

How to read an xml file sent via http post

How to read an xml file sent via http post


——————————————————————————–

I’ve tried a few solutions

$xml = new SimpleXMLElement($_POST);

This gives and error

Fatal error: Uncaught exception ‘Exception’ with message ‘SimpleXMLElement::__construct() expects parameter 1 to be string, array given’ in C:InetpubSitesACRtest.php:12 Stack trace: #0 C:InetpubSitesACRtest.php(12): SimpleXMLElement->__construct(Array) #1 {main} thrown

Fatal error: Call to undefined function simple_xml_loadstring() in

Yet I know the function itself works because I have used it with curl when I have received a string back

$reply = curl_exec($ch);
$xml=simplexml_load_string($reply);

So I assume my problem is my $_POST is a array and not a string. So my question is how to extract my xml from my post variable so I can read it correctly

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@stephan_gerlachApr 03.2008 — When you submit a file via a form it is not in $_POST. It is in $_FILES.

You need to store the file on your server and open it then from there.
Copy linkTweet thisAlerts:
@michaelh613authorApr 03.2008 — Found the complete solution to my problem

$postText = trim(file_get_contents('php://input'));
×

Success!

Help @michaelh613 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...