doushi2902 2013-04-13 09:49
浏览 81

将http发布内容写入php中的文件

I am posting a string xml data to a php page hosted in IIS. All I want is to be able to read the string data that I receive in php page and write it to a file. But am not able to achieve the same. Here is my code:-

<?php
if($_SERVER['REQUEST_METHOD'] == "POST"){ 
echo "Hello
";
$somecontent = print_r($_POST, TRUE);

$my_file = "resp.txt";
$handle = fopen($my_file, "w") or die('Cannot open file:  '.$my_file);
fwrite($handle, $somecontent);  
    }else {
echo "Error
";
    }
 ?>

But am not able to create the file or read the POST contents. I would be glad if someone would figure out how to solve this.

  • 写回答

2条回答 默认 最新

  • dongyong3554 2013-04-13 10:21
    关注

    if you know the input field name then use this.

    <?php
     if($_SERVER['REQUEST_METHOD'] == "POST")
     { 
     echo "Hello
    ";
    
     $somecontent = array();
     $somecontent[] = $_POST['firstname'];
     $somecontent[] = $_POST['lastname'];
     //etc...    
    
     $my_file = "resp.txt";
     $handle = fopen($my_file, "wb") or die('Cannot open file:  '.$my_file);
     fwrite($handle, $somecontent);  
     fclose($handle);
     }
     else {
     echo "Error
    ";
     }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决