没有提示下载CSV文件 [英] Not being prompted to download CSV file
问题描述
我已经在WordPress中创建了一个自定义解决方案,该解决方案将生成CSV文件,方法是单击一个直接链接到该文件的简单超链接来下载该文件.而不是提示您将文件下载到计算机; CSV会在浏览器窗口中打开.
I've created a custom solution in WordPress that will generate a CSV file to be downloaded by clicking a simple hyperlink, linked directly to this file. Instead of being prompted to download the file to the computer; the CSV opens in the the browser window instead.
FWIW,我正在使用香草味的WordPress安装在Media Temple上.
FWIW I'm on Media Temple using a vanilla install of WordPress.
推荐答案
发送正确的mime类型
Send the proper mime type
header('Content-type: text/csv');
并使用Content-Disposition标头指示其下载: http://www. jtricks.com/bits/content_disposition.html
And use the Content-Disposition header to tell it to download: http://www.jtricks.com/bits/content_disposition.html
header('Content-Disposition: attachment; filename="mycssfile.csv"');
您始终希望发送正确的mime类型,否则防火墙,防病毒软件和某些浏览器可能会出现问题...
You always want to send the proper mime type, otherwise firewalls, anti-virus software and some browsers may have issues with it...
这篇关于没有提示下载CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!