display contenute POST


display contenute POST

我想显示POST变量的内容,但我的输出为空。

<?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); 

 ?>

当我调用函数fwrite时,变量$stringData存储在文件中。

这是调用php文件的函数:

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

其中CCD_ 4是阵列。

我尝试使用decode_json等等,但$stringData仍然是空的。

我认为问题出在这里:

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

如果您想在file.txt中存储$_POST的内容,您应该将$_POST['data']转换为类似这样的字符串:

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