简体   繁体   English

php中的header()无法下载文件

[英]header () in php not downloading the file

I am trying to read the file from php and downloading it from the ui on click of a button 我正在尝试从php中读取文件,并单击按钮从ui下载它

<?php
$file = 'download.csv'; //path to the file on disk


if (file_exists($file)) {

    header('Content-Type: application/csv');
    header('Content-Disposition: attachment; filename=contact-list.csv');
    header('Pragma: no-cache');
    readfile($file);
    //unlink($file);

    exit;
}

else {

    print "file not found!!!";
}
?>

But the file is not getting downloaded. 但是该文件未下载。 No error, the code is working. 没有错误,代码正在运行。 unlink() function deleted the file. unlink()函数删除了该文件。

Assuming my comment answers yes to all, then the only think i see that might be an issue. 假设我的评论对所有人都回答是,那么我认为这可能是一个问题。

application/csv 应用程序/ CSV

Should be: 应该:

text/csv 文/ CSV

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM