显示contenute POST

I want to display the contents of the POST variable, but my output is empty.

<?php
 $dir = '/var/www/devData/test';

 // create new directory with 777 permissions if it does not exist yet
 // owner will be the user/group the PHP script is run under
 if ( !file_exists($dir) ) {
  mkdir ($dir, 0777);
 }


         $stringData =  print_r($_POST['data'], true);
         $file = "/var/www/devData/test/ciao.txt"; 
         $fh = fopen($file, 'a+') or die("can't open file");
         $fla = 0;

        $arr = array();
        $i = 0;
        while(!feof($fh)) {
                    $theData = fgets($fh, filesize($file));
                    array_push($arr,$theData);
                    //echo $arr[$i]; 
                    $i++;
         }
         echo $stringData;


         fclose($fh); 



 ?>

When I call the function fwrite, the variable $stringData is stored into the file.

This is the function that calls the php file:

$.post("JS/foo.php", {data: options_label}, function(result){alert(options_label) }, "json");

where options_label is an array.

I tried to use decode_json and so on, but $stringData is still empty.

I think the issue lies here:

$stringData =  print_r($_POST['data'], true);

If you want to store the contents of $_POST in file.txt you should convert $_POST['data'] to a string like so:

$stringData = "";

foreach ($_POST['data'] as $key=>$val) {
    $stringData .= $key . ": " . $val . "
";
}