Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.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_File Handling - Fatal编程技术网

Php 文件下载功能无法附加完整的文件名和扩展名

Php 文件下载功能无法附加完整的文件名和扩展名,php,file-handling,Php,File Handling,我有一个功能,我用它来提示CSV文件下载。但是,文件名在Mozilla浏览器中无法完成,但在Chrome浏览器中效果良好。例如,如果文件名应为F1_Open_marksheet.csv,Mozilla将提示下载为F1(缺少其余的文件名和扩展名。可能是我的代码有问题吗 <?php function pushDownloadFile($filename){ header('Content-Description: File Transfer'); header('Content

我有一个功能,我用它来提示CSV文件下载。但是,文件名在Mozilla浏览器中无法完成,但在Chrome浏览器中效果良好。例如,如果文件名应为F1_Open_marksheet.csv,Mozilla将提示下载为F1(缺少其余的文件名和扩展名。可能是我的代码有问题吗

<?php
function pushDownloadFile($filename){
    header('Content-Description: File Transfer');
    header('Content-Type: text/csv; charset=utf-8');
    header('Content-Disposition: attachment; filename='.$filename);
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($filename));
    ob_clean();
    flush();
    readfile($filename);
    unlink($filename);
}
?>


该漏洞是由文件名中的空格引起的,例如F 1_Open_marksheet.csv,我将其替换为F_1_Open_marksheet.csv的连字符。感谢@CBroe在上面的注释中共享链接。

您的函数缺少右括号
可能重复的