Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 作为变量的头文件名_Php - Fatal编程技术网

Php 作为变量的头文件名

Php 作为变量的头文件名,php,Php,显然第二行给了我一个错误 标头不能包含多个标头,在/storage/ssd1/433/12154433/public_html/FileNa中检测到新行。在线84 我不知道为什么。。。无论何时手动输入文件名都可以,但是,无论何时将文件名作为变量输入,都会抛出此错误。 确保将php开始标记作为第一个字符 当在任何头之前给出任何字符时,它将失败 还要确保退出() 更改为双引号,如下所示: header('Content-Type: text/csv; charset=utf-8'); header

显然第二行给了我一个错误

标头不能包含多个标头,在/storage/ssd1/433/12154433/public_html/FileNa中检测到新行。在线84

我不知道为什么。。。无论何时手动输入文件名都可以,但是,无论何时将文件名作为变量输入,都会抛出此错误。

  • 确保将php开始标记作为第一个字符

  • 当在任何头之前给出任何字符时,它将失败

  • 还要确保退出()


更改为双引号,如下所示:

header('Content-Type: text/csv; charset=utf-8');
header('Content-disposition: attachment;filename="'.$this->fileName.'"'); 

什么是
var\u转储($this->fileName)
给你?它返回string(2241)“Test name@vivek_23所以它返回
Test name
?文件名的扩展名是什么?
.csv
?string(2241)对于文件名来说太多了。你确定它不是文件的内容吗?是的,它是一个.csv谢谢你的回复,我试过了,但还是没有运气
<?php

// Your class things

header("Content-Type: text/csv; charset=utf-8");
header("Content-Disposition: attachment; filename=$this->fileName");

// Your output things

exit();