我已尝试了几个选项,但文本文件正确保存在根服务器中,但我希望用户下载文本文件并保存在他的计算机中。我使用
获得了下载结果header("Content-type: text/plain");
header("Content-Disposition: attachment; filename={$file}");
它会在用户计算机上下载整个脚本,而不是仅下载“text”结果$textToWrite
,我想下载它。我试过的代码如下:
$textToWrite = "$cdacode"."$cda_name"."$subofcode"."$subofname"."$name_payee"."$acno2"."$ifsc"."$micr_cd"."$act_type"."$pay_amt"."00"."DV NO"."$pmt_ref_no"."$paybydate"."$vendcode"."$vend_add"."$bill_num"."$billdate"."$narration"."$emailid"."$mob_num"."$addn_field";
$file= "$cmpno.txt" ;
$current .= "$textToWrite";
file_put_contents($file, $current);
header("Content-type: text/plain");
header("Content-Disposition: attachment; filename={$file}");
答案 0 :(得分:0)
试试这个:
$textToWrite = "$cdacode"."$cda_name"."$subofcode"."$subofname"."$name_payee"."$acno2"."$ifsc"."$micr_cd"."$act_type"."$pay_amt"."00"."DV NO"."$pmt_ref_no"."$paybydate"."$vendcode"."$vend_add"."$bill_num"."$billdate"."$narration"."$emailid"."$mob_num"."$addn_field";
$file= "$cmpno.txt" ;
$current .= "$textToWrite";
file_put_contents($file, $current);
header("Content-type: text/plain");
header("Content-Disposition: attachment; filename={$file}");
readfile($file);
答案 1 :(得分:0)
根据我的评论:据我所知,代码有两个问题:
试试这段代码:
<?php
// @todo This rather needs tidying up
$textToWrite = "$cdacode"."$cda_name"."$subofcode"."$subofname".
"$name_payee"."$acno2"."$ifsc"."$micr_cd"."$act_type".
"$pay_amt"."00"."DV NO"."$pmt_ref_no"."$paybydate"."$vendcode".
"$vend_add"."$bill_num"."$billdate"."$narration".
"$emailid"."$mob_num"."$addn_field";
$file= "$cmpno.txt";
header("Content-type: text/plain");
header("Content-Disposition: attachment; filename={$file}");
echo $textToWrite;
根据我的评论,字符串有点混乱 - 首先尝试看看我们是否在正确的轨道上,如果广泛有效,我会告诉你如何整理它。