【问题标题】:How to create an empty csv file in php?如何在 php 中创建一个空的 csv 文件?
【发布时间】:2018-04-03 09:48:25
【问题描述】:

我尝试过创建创建,但我不知道如何下载。如何创建一个可以在网页上查看、在 php 中操作和下载的空 CSV 文件?

 <?php
             $new_csv= fopen('/scoresheet.csv' , 'w');
             fputcsv($new_csv, $row);
             fclose($new_csv);

             header("content-type:text/csv");
             header("content-disposition:attachment; filename=scoresheet.csv");
             readfile("/scoresheet.csv");
            ?>
            <a href='excel.php?request=".$id."' class='btn btn-primary'>Download</a>

【问题讨论】:

标签: php fopen


【解决方案1】:

您可以使用 file_put_contents() 生成文件

file_put_contents('file.csv', $content);

您可以使用 file_get_contents() 将文件输出到您的网页上

file_get_contents('file.csv');

【讨论】:

  • 我不明白..我只是一个新手
猜你喜欢
  • 1970-01-01
  • 2014-06-09
  • 2010-09-18
  • 2013-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多