doudao1282 2016-06-08 21:44
浏览 55

Array不会使用HTML和PHP写入.csv文件

I am trying to get a feedback form to write the survey responses from the HTML form into a .csv file to my directory, using PHP. The directory already has permissions to be written to, from a website. However, the file still won't write to the .csv file. I have checked and the data is being stored in the array, but it won't write into the .csv file. Here is the PHP code:

<?php

$understand = $_POST["understand"];
$helpful = $_POST["helpful"];
$rank = $_POST["rank"];

$list = array($understand, $helpful, $rank);

echo $list;

echo '<pre>'; print_r($list); echo '</pre>';

var_dump($list);

$file = fopen("/survey-answers/mylist.csv","a");
if(!$file) echo("<pre>Can't open file </pre>");

foreach ($list as $line)  {
fputcsv($file,explode(',',$line));  }

fclose($file);

?>
  • 写回答

1条回答 默认 最新

  • doumen5087 2016-06-08 22:03
    关注

    Most probably you have an issue with this line:

    $file = fopen("/survey-answers/mylist.csv","a");

    This tells PHP to open a a directory in the path /survey-answers/, which mostly doesn't exist. If you are trying to save your CSV into a sub-directory of the current directory then you need to change that to:

    $file = fopen("./survey-answers/mylist.csv","a");

    or if you want to save it into a sub-directory of parent directory then you need to change that to

    $file = fopen("../survey-answers/mylist.csv","a");

    The path is very important to be correct in order your code to work.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?