0

I am getting xmlrpc xml posted to my server and I want to catch the xml and store it in a text file for later processing.

This is what I have, but I just get a blank text file

$getXML = file_get_contents('php://input');
 $xml = new SimpleXMLElement($getXML);
 $text = $xml->Text;

 $today = date("Y-m-d");

 $randomnr = rand(100000, 999999);
 $datet = date("Ymd-H:i:s");
 $filename = "/var/www/".$datet."-".$randomnr.".txt";


 $fh = fopen($filename, 'w') or die("can't open file");
 fwrite($fh, $text);
 fclose($fh);

Can anyone see why I cam getting a blank text file?

hakre
  • 193,403
  • 52
  • 435
  • 836
David
  • 3,927
  • 6
  • 30
  • 48
  • fwrite() returns the number of bytes written, or FALSE on error. - Which value does it return in your case? What is `var_dump(`$text`);`? – hakre Apr 06 '13 at 00:09
  • 1
    Are you _sure_ `$xml->Text;` exist? What if you save `$xml->asXML();` instead? (or the raw `$getXML`?) – Wrikken Apr 06 '13 at 00:16

1 Answers1

0

I found This answer for your question

1)HTTP POST data is usually populated in $_POST, php://input will usually contain PUT data.

2)php://input cannot be opened/read when receiving a multipart/form-data POST, maybe that's what changed client-sided? – Wrikken Mar 28 at 20:01

file_get_contents('php://input') keeps returning empty

php://input returns empty

php://input returning empty string

Community
  • 1
  • 1
mohammad mohsenipur
  • 3,218
  • 2
  • 17
  • 22