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.