doupi4649 2012-07-31 19:12
浏览 18
已采纳

显示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.

  • 写回答

1条回答 默认 最新

  • duanlu1959 2012-07-31 19:57
    关注

    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 . "
    ";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!